Qore Programming Language Reference Manual
0.8.11.1
|
The Gate class implements a reentrant thread lock. More...
Public Member Functions | |
constructor () | |
Creates a new Gate object. More... | |
copy () | |
Creates a new Gate object, not based on the original. More... | |
destructor () | |
Destroys the Gate object. More... | |
int | enter (timeout timeout_ms) |
Acquires the lock if it is unlocked or locked by the same thread, otherwise blocks until the lock counter reaches zero. More... | |
nothing | enter () |
Increments the lock count if the lock is unlocked or already owned by the same thread, otherwise blocks until the lock counter reaches zero. More... | |
int | exit () |
Decrements the lock counter; if it reaches zero then the lock is unlocked and any blocked threads are awoken; in this case 0 is returned; in all other cases, non-zero is returned. More... | |
int | numInside () |
Returns the current lock count. More... | |
int | numWaiting () |
Returns the number of threads blocked on the Gate. More... | |
int | tryEnter () |
Acquires the lock if it is unlocked or locked by the same thread, in which case this method returns 0, otherwise returns immediately with -1. More... | |
The Gate class implements a reentrant thread lock.
Once a thread grabs the lock, it can call the Gate::enter() method again without blocking. Other threads that try to enter the lock will block until the thread holding the lock calls Gate::exit() an equal number of times to Gate::enter() calls.
See the AutoGate class for a class that assists in exception-safe Gate locking.
Additionally, the on_exit statement can provide exception-safe Gate handling at the lexical block level as in the following example:
Qore::Thread::Gate::constructor | ( | ) |
Creates a new Gate object.
Qore::Thread::Gate::copy | ( | ) |
Creates a new Gate object, not based on the original.
Qore::Thread::Gate::destructor | ( | ) |
Destroys the Gate 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 in each thread blocked on this object when it is deleted.
LOCK-ERROR | Object deleted while other threads blocked on it |
int Qore::Thread::Gate::enter | ( | timeout | timeout_ms | ) |
Acquires the lock if it is unlocked or locked by the same thread, otherwise blocks until the lock counter reaches zero.
timeout_ms | a timeout value to wait to acquire the lock (enter the Gate); integers are interpreted as milliseconds; relative date/time values are interpreted literally (with a resolution of milliseconds) |
LOCK-ERROR | object deleted in another thread, etc |
THREAD-DEADLOCK | a deadlock was detected while trying to acquire the lock |
nothing Qore::Thread::Gate::enter | ( | ) |
Increments the lock count if the lock is unlocked or already owned by the same thread, otherwise blocks until the lock counter reaches zero.
LOCK-ERROR | object deleted in another thread, etc |
THREAD-DEADLOCK | a deadlock was detected while trying to acquire the lock |
int Qore::Thread::Gate::exit | ( | ) |
Decrements the lock counter; if it reaches zero then the lock is unlocked and any blocked threads are awoken; in this case 0 is returned; in all other cases, non-zero is returned.
LOCK-ERROR | lock not owned by the current thread, object deleted in another thread, etc |
int Qore::Thread::Gate::numInside | ( | ) |
Returns the current lock count.
int Qore::Thread::Gate::numWaiting | ( | ) |
int Qore::Thread::Gate::tryEnter | ( | ) |
Acquires the lock if it is unlocked or locked by the same thread, in which case this method returns 0, otherwise returns immediately with -1.
LOCK-ERROR | object deleted in another thread, etc |