Condition class provides communication, the ability to wait for some shared resource to reach some desired state, or to signal that it has reached some state in which another thread may be interested.
More...
#include <B2BITS_Condition.h>
|
void | broadcast () |
| Broadcasts condition, waking all current waiters.
|
|
| Condition () |
| Constructor.
|
|
void | signal () |
| Signals condition, waking one waiting thread.
|
|
bool | timedWait (Mutex *apMutex, u64 aTimeout) |
| Waits on condition, until awaked by a signal or broadcast, or until a specified amount of time has elapsed.
|
|
void | wait (Mutex *apMutex) |
| Waits on condition, until awakened by a signal or broadcast.
|
|
| ~Condition () |
| Destructor.
|
|
Condition class provides communication, the ability to wait for some shared resource to reach some desired state, or to signal that it has reached some state in which another thread may be interested.
Each condition variable is closely associated with a mutex that protects the state of the resource.
- Note
- A conditional variable wait always returns with the mutex locked.
- Warning
- Conditional variables are for signaling, not for mutual exclusion.
- Note
- Conditional variables and thier predicates are "linked" - for best results, treat them that way!
◆ Condition()
System::Condition::Condition |
( |
| ) |
|
◆ ~Condition()
System::Condition::~Condition |
( |
| ) |
|
◆ broadcast()
void System::Condition::broadcast |
( |
| ) |
|
Broadcasts condition, waking all current waiters.
- Note
- Use when more than one waiter may respond to predicate change or if any waiting thread may not be able to respond.
- Exceptions
-
◆ signal()
void System::Condition::signal |
( |
| ) |
|
Signals condition, waking one waiting thread.
- Note
- Use when any waiter can respond, and only one need respond. All waiters are equal.
- Exceptions
-
◆ timedWait()
bool System::Condition::timedWait |
( |
Mutex * | apMutex, |
|
|
u64 | aTimeout ) |
Waits on condition, until awaked by a signal or broadcast, or until a specified amount of time has elapsed.
If awaked by a signal or broadcast returns true, otherwise false. The current thread must own specified mutex.
- Note
- The function shall block on a condition variable. It shall be called with mutex locked by the calling thread or undefined behavior results. Upon successful return, the mutex shall have been locked and shall be owned by the calling thread.
- Parameters
-
aTimeout | the maximum time to wait in milliseconds. |
apMutex | System::Mutex object on which to wait. |
- Exceptions
-
◆ wait()
void System::Condition::wait |
( |
Mutex * | apMutex | ) |
|
Waits on condition, until awakened by a signal or broadcast.
The current thread must own specified mutex.
- Exceptions
-
- Note
- The function shall block on a condition variable. It shall be called with mutex locked by the calling thread or undefined behavior results. Upon successful return, the mutex shall have been locked and shall be owned by the calling thread.