![]() |
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 initial=1) | |
| Initialize semaphore with given count. | |
| FXint | value () const |
| Get semaphore value. | |
| void | wait () |
| Decrement semaphore, waiting if count is zero. | |
| FXbool | trywait () |
| Decrement semaphore; returning false if count is zero. | |
| void | post () |
| Increment semaphore. | |
| ~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.
|
|