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 More... | |
void | p () |
Wait for access to the critical area. More... | |
void | v () |
Leave the critical area. More... | |
Public Member Functions inherited from Waitingroom | |
Waitingroom () | |
Constructor. More... | |
virtual | ~Waitingroom () |
Destructor. More... | |
virtual void | remove (Thread *customer) |
Remove a given thread prematurely from the Waitingroom. | |
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.