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


Other Supports from ISA

  • Some processors support TestAndSet instruction.
    boolean TestAndSet(boolean *mem) {
    boolean ret = *mem;
    *mem = TRUE;
    return ret;
    }
  • Acquire Lock:
    while TestAndSet(&lock) ;
  • Release Lock:
    lock = false;

Support From The OS

  • If OS is non-preemptive
    • System calls can be provided for
      • Acquire Lock and Release Lock.
    • Process can not be preempted while acquiring and releasing locks.
  • If OS is preemptive.
    • System calls are tricky to support but not impossible.