Module 21: Problem and Solution
  Lecture 41: Solution to Critical Section Problem
 


Solution Issues

  • Preemptive kernel
    • A process may be preempted when in kernel mode
  • Non-preemptive kernel
    • A process may not be preempted when in kernel mode
  • Preemptive kernels are difficult
    • Especially for SMP machines.
  • Threads on multi-processors face independent OS.
  • Preemptive kernels are essential
    • In embedded systems with RT guarantees
  • Windows 2000, XP are non-preemptive
  • Linux kernel became preemptive since Linux 2.6

Two Process Critical Section Solution

  • Processes are P0 and P1.
  • Processes share a common variable turn(=0 or 1).
  • If turn= i, Pi is permitted to enter the critical section.
while (1) {
While (turn != i);
Critical section
turn = 1-i;
Remainder section
}