Class Semaphore

Class Semaphore

Placement in the overall structure

Module
meeting
Base classes
Waitingroom
Derived classes
Guarded_Semaphore
Time of creation
Task 6
Files
semaphore.h and semaphore.cc

Description

The class Semaphore implements the synchronization concept of the counting semaphore. It inherits the required waiting list from its base class Waitingroom.

Public methods

Semaphore (int c)
The constructor initializes the semaphore counter with the specified value c.
void p ()
Wait operation: If the semaphore counter is greater than zero, it is decremented by one only. Otherwise, the currently running process (a Customer object) is added to the waiting list and is blocked.
void v ()
Release operation: If there is at least one customer on the waiting list, the first of them will be woken up. Otherwise, the semaphore counter is incremented by one.
void wait ()
This method is just another name for the method p().
void signal ()
This method is just another name for the method v().

Notes

To ensure that the call to wait() and signal() does not cost more than to p() and v(), these two methods should be defined as inline.