Qore Programming Language Reference Manual 1.14.2
|
Implements a class that can be used for blocking a thread until a counter reaches zero. More...
#include <QC_Counter.dox.h>
Public Member Methods | |
constructor (softint c=0) | |
Creates the Counter object. More... | |
copy () | |
Creates a new Counter object with the same count as the original. More... | |
int | dec () |
Atomically decrements the counter value. More... | |
destructor () | |
Destroys the Counter object. More... | |
int | getCount () |
Returns the current counter value. More... | |
int | getWaiting () |
Returns the number of threads currently blocked on this object. More... | |
int | inc () |
Atomically increments the counter value. More... | |
nothing | waitForZero () |
Blocks a thread until the counter reaches zero. More... | |
int | waitForZero (timeout timeout_ms) |
Blocks a thread until the counter reaches zero. More... | |
Implements a class that can be used for blocking a thread until a counter reaches zero.
Counter objects allow Qore threads to sleep until a counter reaches zero.
Qore::Thread::Counter::constructor | ( | softint | c = 0 | ) |
Qore::Thread::Counter::copy | ( | ) |
Creates a new Counter object with the same count as the original.
int Qore::Thread::Counter::dec | ( | ) |
Atomically decrements the counter value.
A COUNTER-ERROR
exception can be thrown if the object is deleted in another thread while this call is in progress; this is a race condition caused by a user programming error and should not occur in practice with correct code.
Qore::Thread::Counter::destructor | ( | ) |
Destroys the Counter object.
Note that it is a programming error to delete this object while other threads are blocked on it; in this case an exception is thrown in the deleting thread, and also in each thread blocked on this object when it is deleted.
COUNTER-ERROR | Object deleted while other threads blocked on it |
int Qore::Thread::Counter::getCount | ( | ) |
Returns the current counter value.
int Qore::Thread::Counter::getWaiting | ( | ) |
Returns the number of threads currently blocked on this object.
int Qore::Thread::Counter::inc | ( | ) |
Atomically increments the counter value.
nothing Qore::Thread::Counter::waitForZero | ( | ) |
Blocks a thread until the counter reaches zero.
COUNTER-ERROR | Counter has been deleted in another thread |
int Qore::Thread::Counter::waitForZero | ( | timeout | timeout_ms | ) |
Blocks a thread until the counter reaches zero.
timeout_ms | a timeout value to wait for the Counter to reach zero; integers are interpreted as milliseconds; relative date/time values are interpreted literally (with a resolution of milliseconds) |
COUNTER-ERROR | Counter has been deleted in another thread |