condition


A condition is a synchronization object that enables a thread to test an arbitrary condition and block until the state of the condition changes, all under the protection of a mutex. If the condition is false, a thread blocks on a condition variable and atomically releases the mutex that is waiting for the condition to change. If another thread changes the condition, it may wake up waiting threads by signaling the associated condition variable. The waiting threads, upon awakening, reacquire the mutex and re-evaluate the condition.

Library

Thread<ToolKit>

Declaration

#include <ospace/thread/condition.h>

class os_condition

Interface

Constructor
os_condition( os_condition_mutex& mutex )
Constructs a condition associated with mutex .

Throws: os_thread_toolkit_error

Destructor
~os_condition()
Destroys this condition.
signal
void signal()
Signals a change in the state of this condition, awakening a single waiting thread. Calling signal() has no effect if there are no threads waiting on this condition. The calling thread must own the condition mutex when calling this member function to provide predictable scheduling of awakened threads and to guarantee proper internal synchronization. The behavior of this member function is undefined if the calling thread does not own the condition mutex.

Throws: os_thread_toolkit_error

signal_all
void signal_all()
Signals a change in the state of this condition, awakening all waiting threads. Calling signal_all() has no effect if there are no threads waiting on this condition. The calling thread must own the condition mutex when calling this member function to provide predictable scheduling of awakened threads and to guarantee proper internal synchronization. The behavior of this member function is undefined if the calling thread does not own the condition mutex.

Throws: os_thread_toolkit_error

wait
void wait()
Atomically releases the mutex associated with this condition and waits for this condition to signal a change in state. The calling thread must own the condition mutex condition when calling this member function. The behavior of this member function is undefined if the calling thread does not own the condition mutex. Upon return the condition mutex is re-acquired for the calling thread.

Throws: os_thread_toolkit_error

wait
bool wait( long milliseconds )
Atomically releases the mutex associated with this condition and waits for this condition to signal a change in state. The calling thread must own the condition mutex condition when calling this member function. The behavior of this member function is undefined if the calling thread does not own the condition mutex. Upon return the condition mutex is re-acquired for the calling thread. Returns true if this condition signals a change in state within milliseconds .

Throws: os_thread_toolkit_error


Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.