TinyThread++: condition_variable Class Reference

# condition_variable Class Reference

Condition variable class. More...

`#include <tinythread.h>`

List of all members.

## Public Member Functions
| condition_variable ()
| Constructor.
| ~condition_variable ()
| Destructor.
template<class _mutexT >
void | wait (_mutexT &aMutex)
| Wait for the condition.
void | notify_one ()
| Notify one thread that is waiting for the condition.
void | notify_all ()
| Notify all threads that are waiting for the condition.

## Detailed Description

Condition variable class.

This is a signalling object for synchronizing the execution flow for several threads. Example usage:

     // Shared data and associated mutex and condition variable objects
     int count;
     mutex m;
     condition_variable cond;

     // Wait for the counter to reach a certain number
     void wait_counter(int targetCount)
     {
       lock_guard<mutex> guard(m);
       while(count < targetCount)
         cond.wait(m);
     }

     // Increment the counter, and notify waiting threads
     void increment()
     {
       lock_guard<mutex> guard(m);
       ++ count;
       cond.notify_all();
     }

## Member Function Documentation

void notify_all | ( |  | ) | `[inline]`

Notify all threads that are waiting for the condition.

All threads that are blocked waiting for this condition variable will be woken up.

Note:
  Only threads that started waiting prior to this call will be woken up.

void notify_one | ( |  | ) | `[inline]`

Notify one thread that is waiting for the condition.

If at least one thread is blocked waiting for this condition variable, one will be woken up.

Note:
  Only threads that started waiting prior to this call will be woken up.

void wait | ( | _mutexT & | aMutex | ) | `[inline]`

Wait for the condition.

The function will block the calling thread until the condition variable is woken by `notify_one()`, `notify_all()` or a spurious wake up.

Parameters:

  `[in]` | aMutex | A mutex that will be unlocked when the wait operation starts, an locked again as soon as the wait operation is finished.

The documentation for this class was generated from the following file:

- tinythread.h