BIT204 · 2082 · 10 marks
Question Differentiate between user thread and kernel thread. Given the following information about processes, compute the average waiting time and turnaround time for FCFS and Round Robin (Quantum = 2). | Processes | CPU Burst Time | Arrival Time | |-----------|----------------|--------------| | A
Question
Differentiate between user thread and kernel thread. Given the following information about processes, compute the average waiting time and turnaround time for FCFS and Round Robin (Quantum = 2).
| Processes | CPU Burst Time | Arrival Time |
|---|---|---|
| A | 9 | 2 |
| B | 11 | 1 |
| C | 1 | 0 |
| D | 2 | 3 |
| E | 7 | 4 |
[2+8]
User Thread vs Kernel Thread
| Feature | User Thread | Kernel Thread |
|---|---|---|
| Management | Managed by a user-level thread library | Managed directly by the OS kernel |
| Kernel awareness | Kernel is unaware of them | Kernel is aware and schedules them |
| Context switch | Fast, no kernel mode switch | Slower, requires kernel mode switch |
| Blocking | One blocking thread blocks whole process | Other threads continue running |
| Portability | Portable, runs on any OS | OS dependent |
| Example | POSIX Pthreads (user), Java green threads | Windows threads, Linux kernel threads |
Given Data
| Process | Burst | Arrival |
|---|---|---|
| A | 9 | 2 |
| B | 11 | 1 |
| C | 1 | 0 |
| D | 2 | 3 |
| E | 7 | 4 |
Quantum $= 2$.
(a) FCFS
Order by arrival: C(0), B(1), A(2), D(3), E(4).
| Process | Arr | Burst | Start | Finish | TAT | WT |
|---|---|---|---|---|---|---|
| C | 0 | 1 | 0 | 1 | 1 | 0 |
| B | 1 | 11 | 1 | 12 | 11 | 0 |
| A | 2 | 9 | 12 | 21 | 19 | 10 |
| D | 3 | 2 | 21 | 23 | 20 | 18 |
| E | 4 | 7 | 23 | 30 | 26 | 19 |
$$\text{Avg TAT} = \frac{1+11+19+20+26}{5} = \frac{77}{5} = 15.4$$
$$\text{Avg WT} = \frac{0+0+10+18+19}{5} = \frac{47}{5} = 9.4$$
(b) Round Robin (Quantum = 2)
Enqueue rule: a newly arriving process is added to the ready queue before the just-preempted process is re-added.
Tracing:
- t=0: only C ready. Run C(1) → t=1, C done.
- t=1: B arrives, queue [B]. Run B → t=3, B rem 9. During run, A arrives at 2, D arrives at 3. Queue after adding arrivals then B: [A, D, B].
- t=3: Run A → t=5, A rem 7. E arrives at 4. Queue: [D, B, E, A].
- t=5: Run D(2) → t=7, D done. Queue: [B, E, A].
- t=7: Run B → t=9, B rem 7. Queue: [E, A, B].
- t=9: Run E → t=11, E rem 5. Queue: [A, B, E].
- t=11: Run A → t=13, A rem 5. Queue: [B, E, A].
- t=13: Run B → t=15, B rem 5. Queue: [E, A, B].
- t=15: Run E → t=17, E rem 3. Queue: [A, B, E].
- t=17: Run A → t=19, A rem 3. Queue: [B, E, A].
- t=19: Run B → t=21, B rem 3. Queue: [E, A, B].
- t=21: Run E → t=23, E rem 1. Queue: [A, B, E].
- t=23: Run A → t=25, A rem 1. Queue: [B, E, A].
- t=25: Run B → t=27, B rem 1. Queue: [E, A, B].
- t=27: Run E(1) → t=28, E done. Queue: [A, B].
- t=28: Run A(1) → t=29, A done. Queue: [B].
- t=29: Run B(1) → t=30, B done.
Gantt Chart:
C | B | A | D | B | E | A | B | E | A | B | E | A | B | E | A | B
0 1 3 5 7 9 11 13 15 17 19 21 23 25 27 28 29 30
Completion / TAT / WT
| Process | Arr | Burst | Finish | TAT = F−A | WT = TAT−B |
|---|---|---|---|---|---|
| C | 0 | 1 | 1 | 1 | 0 |
| B | 1 | 11 | 30 | 29 | 18 |
| A | 2 | 9 | 29 | 27 | 18 |
| D | 3 | 2 | 7 | 4 | 2 |
| E | 4 | 7 | 28 | 24 | 17 |
$$\text{Avg TAT} = \frac{1+29+27+4+24}{5} = \frac{85}{5} = 17.0$$
$$\text{Avg WT} = \frac{0+18+18+2+17}{5} = \frac{55}{5} = 11.0$$
Summary
| Metric | FCFS | Round Robin (Q=2) |
|---|---|---|
| Avg Turnaround Time | 15.4 | 17.0 |
| Avg Waiting Time | 9.4 | 11.0 |
Watch the Round Robin queue order: using the standard enqueue convention (new arrivals join the ready queue before the preempted process), B finishes at 30 and A at 29, giving Avg TAT = 17.0 and Avg WT = 11.0. A different enqueue order, for example running D at t = 6 to 8, gives finish times B = 29 and A = 27 instead. FCFS is unaffected.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.