Is an object that is faciliates many threads to wait for something to happen. More...
Public Member Functions | |
| ConditionVar () | |
| ConditionVar (const ConditionVar &) | |
| ~ConditionVar () | |
| void | wait () |
| void | signal (bool all) |
Protected Attributes | |
| QWaitCondition * | cond_ |
Is an object that is faciliates many threads to wait for something to happen.
Usage:
From the working thread 1. lock() You will now be the only one allowed to check weather condition is true (e.g. if new work has arrived).
2. Check condition. If false, call wait(). You will now sleep until someone calls signal(); If you are awakened, check the condition again and go back to sleep if it is false.
3. If condition is true, unLock() and start working. When finished working go back to 1.
It is wise to put an exit flag in the loop, so it's possible to say that we are about to quit.
From the manager: When you want to change the condition: 1. lock 2. set condition (e.g. add more work) 3. signal 4. unLock
| Threads::ConditionVar::ConditionVar | ( | ) |
| Threads::ConditionVar::ConditionVar | ( | const ConditionVar & | ) |
| Threads::ConditionVar::~ConditionVar | ( | ) |
| void Threads::ConditionVar::signal | ( | bool | all | ) |
If all is true, all threads that have called wait() will be Notified about the signal. If all is false, only one thread will respond.
| void Threads::ConditionVar::wait | ( | ) |
QWaitCondition* Threads::ConditionVar::cond_ [protected] |
1.7.1