![]() |
PIP 5.5.3
Platform-Independent Primitives
|
Basic semaphore. More...
#include <pisemaphore.h>
Public Member Functions | |
| PISemaphore | PISemaphore (int initial=0) |
| Constructs semaphore with "initial" available resources. | |
| ~PISemaphore () | |
| Destroy semaphore. | |
| void | acquire (int cnt=1) |
| Acquire "cnt" resources. If no available resources, than blocks until they freed. | |
| bool | tryAcquire (int cnt=1) |
| Try to acquire "cnt" resources. Returns if operation was successfull. | |
| bool | tryAcquire (int cnt, PISystemTime timeout) |
| Try to acquire "cnt" resources for "timeout". Returns if operation was successfull (timeout has not expired). | |
| void | release (int cnt=1) |
| Release "cnt" resources. | |
| int | available () const |
| Returns available resources count. | |
Basic semaphore.
PISemaphore provides critical code section defence between several threads with resource counting. Semaphore contains logic counter and functions to change it: release(), acquire() and tryAcquire().
For automatic acquire-release use PISemaphoreLocker.