event_semaphore


To coordinate the actions of several threads based on a single event, use an event semaphore. For example, in a stock broking system, you might want several different thread-controlled activities to occur when a stock price changes. An event semaphore can exist either in an unposted state or in a posted state. In an unposted state, all threads that perform a wait will block. In a posted state, no threads that perform a wait will block. If an event semaphore is pulsed when in an unposted state, all waiting semaphores will immediately unblock. If an event semaphore is moved to a posted state from an unposted state, all waiting semaphores will immediately unblock.

Library

Thread<ToolKit>

Declaration

#include <ospace/thread/eventsem.h>

class os_event_semaphore

Interface

Constructor
os_event_semaphore( bool posted )
Constructs an event semaphore. The variable posted (default false ) indicates whether the event semaphore is initially created in the posted or unposted state.

Throws: os_thread_toolkit_error

Destructor
~os_event_semaphore()
Destroys this semaphore, releasing any associated system resources.
post
void post()
Sets state to posted. All threads waiting for the event semaphore will immediately unblock, and subsequent threads that wait for the event semaphore will not block. This is the antonym of reset() .

Throws: os_thread_toolkit_error

posted
bool posted()
Returns true if posted.

Throws: os_thread_toolkit_error

print
void print( ostream& stream ) const
Prints to stream .

Throws: os_thread_toolkit_error

pulse
void pulse()
Sets the event semaphore to a posted state, thus allowing all blocked threads to awaken; then, immediately resets the event semaphore.

Throws: os_thread_toolkit_error

reset
void reset()
Resets state. Subsequent threads waiting for the event semaphore will block until the event semaphore becomes posted again.

Throws: os_thread_toolkit_error

wait
void wait()
Waits until the event semaphore becomes posted. If the event semaphore is already in a posted state, returns immediately.

Throws: os_thread_toolkit_error


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