About
A condition variable is used to wake a waiting thread to perform some action. It is typically used together with custom threads, see Threads Manual.
Condition
A condition variable is based on maxon::ConditionVariableInterface:
- Warning
- Waiting for a condition variable in a job might result in a deadlock. Consider using LazyInit or LazyInitThreaded for initialization instead.
A condition variable can have multiple dependencies. This means that Set()
must be called multiple times:
A condition variable is typically used as a member variable of a custom thread:
{
public:
~ExampleThread() { }
{
}
maxon::Result<
void> operator ()()
{
{
if (_condition.Wait(timeValue))
{
_condition.Clear();
}
}
}
void Action()
{
_condition.Set();
}
private:
maxon::ConditionVariableRef _condition;
};
This example thread can be used like this:
if (!g_exampleThread)
{
}
if (g_exampleThread)
{
g_exampleThread->Action();
}
Further Reading