CS 3733 Operating Systems


Lecture 18 [10/27/97]: Semaphores

Reading: PUP Section 8.2)

  • Semaphore: an integer variable P which can only be accessed through two atomic operations: wait (P) and signal (V). (Note: Tanenbaum calls these DOWN and UP.)

  • An atomic operation is one that can't be interrupted so once a process starts the operation, it is guaranteed that no one will mess it up. (As discussed in class last lecture, the notion of can't be interrupted is subtle.)

  • Implementation of semaphores with busy waiting
    wait(S):                                signal(S):
        while (S <= 0) ;                        S = S + 1;
        S = S - 1;
    

  • Use Test-and-Set to implement (Pup Exercise 8.11 and Example 8.11)

  • Semaphores can be used for n-process synchronization:
        wait(mutex)
           critical section
        signal(mutex)
           remainder section
    


    Revision Date: 10/27/97