next up previous contents
Next: Special Notes Up: Nachos Threads Previous: Threads & Scheduling

Synchronization and Mutual Exclusion

Low-level Nachos routines (including the ones discussed above) frequently disable and re-enable interrupts to achieve mutual exclusion (e.g., by calling Interrupt::SetLevel()).

Synchronization facilities are provided through semaphores. The Semaphore object provides the following operations:

Semaphore(char* debugName, int initialValue)
The constructor creates a new counting semaphore having an initial value of initialValue. The string debugName is also associated with the semaphore to simplify debugging.
void P()
Decrement the semaphore's count, blocking the caller if the count is zero.
void V()
Increment the semaphore's count, releasing one thread if any are blocked waiting on the count.



Thomas Narten
Mon Feb 3 15:00:27 EST 1997