StuBS
Loading...
Searching...
No Matches
Semaphore Class Reference

Semaphore used for synchronization of threads. More...

#include <semaphore.h>

Inheritance diagram for Semaphore:
Collaboration diagram for Semaphore:

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Semaphore()

Semaphore::Semaphore ( unsigned c = 0)
inlineexplicit

Constructor; initialized the counter with provided value c

Parameters
cInitial counter value

Member Function Documentation

◆ p()

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.

◆ v()

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.


The documentation for this class was generated from the following files: