next up previous contents
Next: The ILock class Up: Reference of Practical Thread Previous: The ISync class

The ISema class

# include  <ucr/ISema.h>
class ISema;

The ISema class implements counting semaphores. Instances of ISema can be incremented or decremented in a thread. Interrupt handlers may also increment a semaphore, but not decrement one. This class is built up from the ISync class.

The decrement method will block the thread if the current value of the semaphore is 0. This is the principle means of synchronization, and is also the reason that interrupt handlers may not decrement semaphores.

The increment method never blocks. Threads and interrupt handlers may call the increment method safely. If the value of the semaphore is zero and a thread is waiting to decrement the semaphore, then an increment causes a single thread to be released and the value left at zero.

Threads are released from the semaphore in FIFO order. There are other theoretically fair policies, but none significantly better then this.



Stephen Williams
9/2/1997