Lock that is bound to a single condition. This is the common usage case of condition variables.
More...
|
| void | wait (UniqueLock< Mutex > &lock) |
| |
| template<class Rep , class Period > |
| bool | wait (UniqueLock< Mutex > &lock, Duration< Rep, Period > time) |
| |
| template<class Clock , class Dur > |
| bool | wait (UniqueLock< Mutex > &lock, TimePoint< Clock, Dur > time) |
| |
| void | wait () |
| | No lock arg required. More...
|
| |
| template<class Rep , class Period > |
| bool | wait (Duration< Rep, Period > time) |
| |
| template<class Clock , class Dur > |
| bool | wait (TimePoint< Clock, Dur > time) |
| |
| void | signal () |
| | Signal one waiting thread to resume, resumed thread attempts to acquire the lock. More...
|
| |
| void | broadcast () |
| | Signal all waiting threads to resume, all resumed threads attempt to acquire the lock. More...
|
| |
| void | wait (UniqueLock< Mutex > &lock) |
| | Release lock and wait until thread is signaled. More...
|
| |
| template<class Rep , class Period > |
| bool | wait (UniqueLock< Mutex > &lock, Duration< Rep, Period > time) |
| | Release lock and wait until thread is signaled or until an amount of time has passed. Returns true if signaled, false if timed out. More...
|
| |
| template<class Clock , class Dur > |
| bool | wait (UniqueLock< Mutex > &lock, TimePoint< Clock, Dur > time) |
| | Release lock and wait until thread is signaled or until a certain time. Returns true if signaled, false if timed out. More...
|
| |
| | Mutex ()=default |
| |
| | Mutex (const Mutex &) |
| | Can't copy, silently inits to default. More...
|
| |
| Mutex & | operator= (const Mutex &) |
| | Can't copy, silently does nothing. More...
|
| |
| void | lock () |
| | Acquire the lock. Thread suspends until lock becomes available. More...
|
| |
| void | unlock () |
| | Release the lock. More...
|
| |
| bool | tryLock () |
| | Attempt to acquire the lock, returns immediately. Returns true if the lock was acquired, false otherwise. More...
|
| |
| Handle & | handle () |
| | Get platform handle. More...
|
| |
Lock that is bound to a single condition. This is the common usage case of condition variables.
Example:
--Consumer Thread--
cond.lock();
while (data < 10) { cond.wait(); }
cond.unlock();
--Producer Thread--
cond.lock();
data++;
cond.signal();
cond.unlock();
The condition must be locked before calling any methods on it.
Due to "spurious wakeups" (wakeups without a signal), conditions should always wait() in a while loop, and the predicate (ex. data < 10) should always be checked.