Public Member Functions | Protected Attributes

Threads::ConditionVar Class Reference

Is an object that is faciliates many threads to wait for something to happen. More...

Inheritance diagram for Threads::ConditionVar:
Threads::Mutex

List of all members.

Public Member Functions

 ConditionVar ()
 ConditionVar (const ConditionVar &)
 ~ConditionVar ()
void wait ()
void signal (bool all)

Protected Attributes

QWaitCondition * cond_

Detailed Description

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


Constructor & Destructor Documentation

Threads::ConditionVar::ConditionVar (  ) 
Threads::ConditionVar::ConditionVar ( const ConditionVar  ) 
Threads::ConditionVar::~ConditionVar (  ) 

Member Function Documentation

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 (  ) 

Member Data Documentation

QWaitCondition* Threads::ConditionVar::cond_ [protected]