Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
A semaphore allows for protection of a resource that can be accessed by a fixed number of simultaneous threads. More...
#include <FXSemaphore.h>
Public Member Functions | |
FXSemaphore (FXint count=1) | |
Initialize semaphore with given count. | |
FXbool | wait () |
Decrement semaphore by 1, waiting if count is zero. More... | |
FXbool | wait (FXTime nsec) |
Try decrement semaphore; return true if successful. More... | |
FXbool | trywait () |
Try decrement semaphore, and return true if successful. More... | |
FXbool | post () |
Increment semaphore by 1. More... | |
~FXSemaphore () | |
Delete semaphore. | |
A semaphore allows for protection of a resource that can be accessed by a fixed number of simultaneous threads.
A typical example of the use of semaphores is for a buffer containing N items. A producer thread may freely append N items before blocking for space to become available; a consumer thread can remove items and block only when no items are left. Thus, two counting semaphores could be used to manage such a buffer, one counting empty slots and one counting filled slots. As long as production and consumption proceed at comparable rates, no thread needs to be suspended.
FXbool FX::FXSemaphore::post | ( | ) |
Increment semaphore by 1.
Return false if an error occurred.
FXbool FX::FXSemaphore::trywait | ( | ) |
Try decrement semaphore, and return true if successful.
Return false if count was zero or if an error occurred.
FXbool FX::FXSemaphore::wait | ( | ) |
Decrement semaphore by 1, waiting if count is zero.
Return false if an error occurred.
FXbool FX::FXSemaphore::wait | ( | FXTime | nsec | ) |
Try decrement semaphore; return true if successful.
Return false if timed out or an error occurred.
Copyright © 1997-2022 Jeroen van der Zijp |