A class for thread synchronization and mutual exclusion. More...
#include <yarp/os/Semaphore.h>
Classes | |
class | Private |
Public Member Functions | |
Semaphore (unsigned int initialCount=1) | |
Constructor. | |
virtual | ~Semaphore () |
Destructor. | |
void | wait () |
Decrement the counter, even if we must wait to do that. | |
bool | waitWithTimeout (double timeoutInSeconds) |
Try to decrement the counter, even if we must wait - but don't wait forever. | |
bool | check () |
Decrement the counter, unless that would require waiting. | |
void | post () |
Increment the counter. | |
A class for thread synchronization and mutual exclusion.
A semaphore has an internal counter. Multiple threads can safely increment or decrement that counter. If one thread attempts to decrement the counter below zero, it must wait for another thread to first increment it. This is a useful primitive for regulating thread interaction.
Definition at line 24 of file Semaphore.h.
Constructor.
Sets the initial value of the counter.
initialCount | initial value of the counter |
Definition at line 86 of file Semaphore.cpp.
|
virtual |
Destructor.
Definition at line 91 of file Semaphore.cpp.
bool Semaphore::check | ( | ) |
Decrement the counter, unless that would require waiting.
If the counter would decrement below zero, this method simply returns without doing anything.
Definition at line 106 of file Semaphore.cpp.
void Semaphore::post | ( | ) |
Increment the counter.
If another thread is waiting to decrement the counter, it is woken up.
Definition at line 111 of file Semaphore.cpp.
void Semaphore::wait | ( | ) |
Decrement the counter, even if we must wait to do that.
If the counter would decrement below zero, the calling thread must stop and wait for another thread to call Semaphore::post on this semaphore.
Definition at line 96 of file Semaphore.cpp.
Try to decrement the counter, even if we must wait - but don't wait forever.
This method wiill wait for at most timeoutInSeconds seconds (this can be fractional). If the counter has not been decremented within that interval, the method will return false.
timeoutInSeconds | the maximum length of time to wait, in seconds (may be fractional). |
Definition at line 101 of file Semaphore.cpp.