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 (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. More...
 
- Public Member Functions inherited from Queue< Thread >
 Queue ()
 Default constructor; initialized the queue as empty.
 
void enqueue (Thread *item)
 Enqueues the provided item at the end of the queue. More...
 
Thread * dequeue ()
 Removes the first element in the queue and returns it. More...
 
Iterator begin ()
 
Iterator end ()
 
Thread * remove (Thread *item, bool(*cmp)(Thread *, Thread *)=[](Thread *a, Thread *b) {return a==b;})
 Removes and returns a single element from the queue. More...
 
void insertFirst (Thread *item)
 Adds item to the beginning of the queue. More...
 
void insertAfter (Thread *old_item, Thread *new_item)
 Inserts the element new_item directly after old_item. More...
 
Thread * first ()
 Returns the first element in the queue without removing it. More...
 
Thread * next (Thread *o)
 Returns the next element in the queue for a given element.
 

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: