StuBS
|
Semaphore used for synchronization of threads. More...
#include <semaphore.h>
Public Member Functions | |
Semaphore (unsigned c=0) | |
Constructor; initialized the counter with provided value c | |
void | p () |
Wait for access to the critical area. | |
void | v () |
Leave the critical area. | |
Public Member Functions inherited from Waitingroom | |
Waitingroom () | |
Constructor. | |
virtual | ~Waitingroom () |
Destructor. | |
virtual void | remove (Thread *customer) |
Remove a given thread prematurely from the Waitingroom. | |
Additional Inherited Members | |
Static Protected Member Functions inherited from Waitingroom | |
static Thread ** | getNext (Thread &th, unsigned i) |
Get the next thread of the queue. | |
Semaphore used for synchronization of threads.
The class Semaphore implements the concept of counting semaphores. The waiting list is provided by the base class Waitingroom.
|
inlineexplicit |
Constructor; initialized the counter with provided value c
c | Initial counter value |
void Semaphore::p | ( | ) |
Wait for access to the critical area.
Enter/Wait operation: If the counter is greater than 0, then it is decremented by one. Otherwise the calling thread will be enqueued into the Waitingroom and marked as blocked.
void Semaphore::v | ( | ) |
Leave the critical area.
Leave operation: If there are threads in the Waitingroom, wake the first one; otherwise increment the counter by one.