Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FX::FXSemaphore Class Reference

A semaphore allows for protection of a resource that can be accessed by a fixed number of simultaneous threads. More...

#include <FXSemaphore.h>

List of all members.

Public Member Functions

 FXSemaphore (FXint count=1)
 Initialize semaphore with given count.
void wait ()
 Decrement semaphore by 1, waiting if count is zero.
FXbool wait (FXTime nsec)
 Try decrement semaphore; return false if timed out.
FXbool trywait ()
 Try decrement semaphore, and return false if count was zero.
void post ()
 Increment semaphore by 1.
 ~FXSemaphore ()
 Delete semaphore.

Detailed Description

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.


The documentation for this class was generated from the following file:

Copyright © 1997-2016 Jeroen van der Zijp