Phase 1Ch 1.2 Threads and IPC
ACompressed recap
Threads share code, globals, heap, files; private stack, registers, PC. User-level threads: fast, all block together; kernel-level: independent, parallel. Models many-to-one, one-to-one, many-to-many. IPC: shared memory (fast, needs sync), message passing (kernel copies, blocking or not), pipes (one-way; named for unrelated processes); producer–consumer waits on full/empty.
BMerged rule card
1.2.1 Threads: what they share, user-level vs kernel-level threads
- Thread = path of execution inside a process; shares code, data, heap, open files; private stack, registers, PC, thread ID.
- Threads are cheaper to create and switch than processes.
- User-level: fast, kernel unaware, one block blocks all, no parallelism. Kernel-level: kernel-scheduled, independent blocking, parallel on multiple cores.
- Models: many-to-one, one-to-one, many-to-many.
1.2.2 Inter-process communication: shared memory, message passing and pipes
- Shared memory: map a common region; fast; programmer synchronizes.
- Message passing: send/receive via the kernel; direct or indirect (mailbox); blocking or non-blocking; works across machines; copies data.
- Ordinary pipe: one-way, parent–child; named pipe (FIFO) for unrelated processes; two-way needs two pipes.
- Producer waits when the buffer is full; consumer waits when empty.
CInterleaved GATE-style questions
Q1 · MCQ · 1 mark(s) — Threads
A process has 4 threads. How many stacks does it have?
- (A) 1
- (B) 2
- (C) 8
- (D) 4
Q2 · MSQ · 2 mark(s) — Kernel threads
Which are advantages of kernel-level threads over user-level threads?
- (A) The kernel can schedule each thread separately.
- (B) Thread switches never involve the kernel.
- (C) A blocking call blocks only that thread.
- (D) Threads can run in parallel on multiple CPUs.
Q3 · MCQ · 1 mark(s) — Sharing
Which of these is NOT shared between threads of the same process?
- (A) Register values
- (B) Heap memory
- (C) Code
- (D) Global variables
Q4 · MCQ · 1 mark(s) — Model
In the many-to-one model, the main drawback is:
- (A) threads cannot share memory
- (B) too many kernel threads
- (C) a blocking system call blocks all threads
- (D) threads cannot be created
Q5 · MCQ · 1 mark(s) — IPC
Which IPC mechanism requires the processes themselves to handle synchronization?
- (A) Blocking pipes
- (B) Mailboxes
- (C) Message passing
- (D) Shared memory
Q6 · NAT · 1 mark(s) — Pipes
Minimum number of ordinary pipes for full two-way communication between 2 processes?
Numerical answer: ________
Q7 · MCQ · 1 mark(s) — Named pipes
Two unrelated processes (not parent and child) want to use a pipe. They should use a:
- (A) shared stack
- (B) ordinary pipe
- (C) named pipe (FIFO)
- (D) thread
Q8 · MCQ · 1 mark(s) — Blocking
A consumer reads from an empty ordinary pipe. It:
- (A) blocks until data is written
- (B) terminates the producer
- (C) reads 0 bytes and crashes
- (D) reads old data
DAnswer Vault
Try the questions first. Open when you are ready to check.
🔐 Open the Answer Vault
Q1 Answer: (D) · 1 mark(s)
One per thread.
- (A) is wrong: Stacks are private.
- (B) is wrong: No.
- (C) is wrong: No.
Re-read: Lesson 1.2.1 — Threads: what they share, user-level vs kernel-level threads
Q2 Answer: (A) (C) (D) · 2 mark(s)
Kernel threads do need the kernel to switch.
- (B) is wrong: That is the user-level advantage.
Re-read: Lesson 1.2.1 — Threads: what they share, user-level vs kernel-level threads
Q3 Answer: (A) · 1 mark(s)
Each thread has its own registers.
- (B) is wrong: Shared.
- (C) is wrong: Shared.
- (D) is wrong: Shared.
Re-read: Lesson 1.2.1 — Threads: what they share, user-level vs kernel-level threads
Q4 Answer: (C) · 1 mark(s)
Only one kernel thread underneath.
- (A) is wrong: They share memory.
- (B) is wrong: There is only one.
- (D) is wrong: They can be created.
Re-read: Lesson 1.2.1 — Threads: what they share, user-level vs kernel-level threads
Q5 Answer: (D) · 1 mark(s)
Plain memory reads and writes.
- (A) is wrong: Blocking provides order.
- (B) is wrong: Kernel-managed.
- (C) is wrong: Built-in ordering.
Re-read: Lesson 1.2.2 — Inter-process communication: shared memory, message passing and pipes
Q6 Answer: 2 · 1 mark(s)
One per direction.
Re-read: Lesson 1.2.2 — Inter-process communication: shared memory, message passing and pipes
Q7 Answer: (C) · 1 mark(s)
It has a name in the file system.
- (A) is wrong: Not a mechanism.
- (B) is wrong: Needs a common ancestor.
- (D) is wrong: Unrelated.
Re-read: Lesson 1.2.2 — Inter-process communication: shared memory, message passing and pipes
Q8 Answer: (A) · 1 mark(s)
Read on an empty pipe waits.
- (B) is wrong: No.
- (C) is wrong: It waits.
- (D) is wrong: No old data exists.
Re-read: Lesson 1.2.2 — Inter-process communication: shared memory, message passing and pipes