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...
|FXSemaphore (FXint count=1)|
|Initialize semaphore with given count. |
|Decrement semaphore by 1, waiting if count is zero. |
|FXbool||wait (FXTime nsec)|
|Try decrement semaphore; return false if timed out. |
|Try decrement semaphore, and return false if count was zero. |
|Increment semaphore by 1. |
|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.
|Copyright © 1997-2016 Jeroen van der Zijp|