Friedrich-Alexander-Universität Erlangen-Nürnberg  /   Technische Fakultät  /   Department Informatik
Semaphore Class Reference

Semaphore used for synchronization of threads. More...

#include <sync/semaphore.h>

+ Inheritance diagram for Semaphore:
+ Collaboration diagram for Semaphore:

Public Member Functions

 Semaphore (int 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
- Public Member Functions inherited from Queue< Thread >

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 ( int  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: