1. University MCA (AI/ML) Semester 1
  2. CAP366
  3. Unit 3

CAP366 · Unit 3: Process management

Threads and multithreading

16 practice questions · in the MTE and ETE syllabus

Key points

  • Threads share code, data and files
  • Each thread has own stack and registers
  • Many-to-one: blocking call blocks the process
  • Amdahl: 1 / (S + (1 - S) / N)

A thread is a unit of CPU execution inside a process. Threads of one process share code, global data and open files; each has its own stack, registers and program counter.

Benefits: responsiveness, cheap resource sharing, cheaper creation and switching than processes, and use of multiple cores.

ModelMappingNote
Many-to-oneMany user threads to one kernel threadOne blocking call blocks all; no parallelism
One-to-oneEach user thread to a kernel threadParallel; cost limits count (Linux, Windows)
Many-to-manyMany user to fewer kernel threadsParallel without one kernel thread each

Amdahl's law: speedup <= 1 / (S + (1 - S) / N). With 60 percent parallel code (S = 0.4) on 3 cores: 1 / (0.4 + 0.2) = 1.67.

Exam pitfall: shared data needs synchronization; counter++ by two threads can lose updates because it is a load, an add and a store.

Try two questions

Question 1 · Tier 3, Apply

In Windows, the basic unit that the kernel scheduler dispatches to a processor is the:

  1. Thread
  2. Process
  3. Fiber
  4. Job object
Show the answer

A. A Windows process is a container for resources; its threads are what the scheduler runs. Fibers are scheduled by the application in user mode and job objects group processes.

Why not B: A process only holds resources; its threads are scheduled.

Why not C: Fibers are scheduled by the application in user mode.

Why not D: A job object groups processes for management.

Question 2 · Tier 2, Understand

In Linux, threads are implemented as:

  1. Library-only user threads that the kernel cannot see or schedule
  2. Tasks created with clone() that share resources such as the address space with their parent
  3. Hardware contexts assigned directly by the BIOS at boot time
  4. Separate processes that are never allowed to share any memory
Show the answer

B. Linux treats a thread as a task created with clone() and chosen sharing flags, so the kernel schedules threads and processes with the same mechanism.

Why not A: Linux threads are kernel-visible and scheduled by the kernel.

Why not C: The BIOS plays no part in creating threads.

Why not D: Threads exist to share memory, such as the address space.