Conditional Variable. More...

#include <rconditionvar.h>

Public Member Functions

 RConditionVar (void)
 
void Wait (RMutex *mutex, unsigned long time=0)
 
void Wait (unsigned long time=0)
 
void WakeUpOne (void)
 
void WakeUpAll (void)
 
virtual ~RConditionVar (void)
 

Private Attributes

pthread_cond_t Cond
 

Detailed Description

Conditional Variable.

The RConditionVar class provides a representation of a conditional variable used for thread synchronization.

Lets suppose that a function func1 (of a given thread) is waiting that some kind of event occurs (for example in a func2 of a second thread). A conditional variable can be used to block to first thread as long as the event occurs.

void func1(void)
{
// Wait that a conditional variable corresponds to a given event
cond.Wait();
// The thread can work now
}
void func2(void)
{
// Do something
cond.WakeUpOne();
// Continue to work
}

Constructor & Destructor Documentation

RConditionVar ( void  )

Construct a conditional variable.

virtual ~RConditionVar ( void  )
virtual

Destruct the conditional variable.

Member Function Documentation

void Wait ( RMutex mutex,
unsigned long  time = 0 
)

Wait that the conditional variable corresponds to a event.

Parameters
mutexMutex associated with the conditional variable.
timeNumber of milliseconds to wait for the conditional variable. If null, the thread waits forever.
void Wait ( unsigned long  time = 0)

Wait that the conditional variable corresponds to a event.

Parameters
timeNumber of milliseconds to wait for the conditional variable. If null, the thread waits forever.
void WakeUpOne ( void  )

Wake up one of the blocked thread by this conditional variable (depending of the priority schema).

void WakeUpAll ( void  )

Wake up all the blocked thread by this conditional vairbale.

Field Documentation

pthread_cond_t Cond
private

The conditional variable structure.