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


Semaphores

  • A data structure abstraction for lock
    class semaphore {
    private: int s;
    public:
    void wait(void) {while (s < 0) ;
    s--;
    }
    void signal(void) {
    s++;
    }
    }

Mutual Exclusion Using Semaphore

semaphore mutex;
:
mutex.wait();
// Critical Section
mutex.signal();
// Remainder Section
: