sentinel


This templatized class provides synchronized access to guarded objects in a multithreaded environment. In addition, os_sentinel can provide change notification to blocked threads when the guarded object is modified. Change detection occurs when the guarded object is released from a lock and does not incur the overhead of a true comparison operation.

Library

Thread<ToolKit>

Declaration

#include <ospace/thread/sentinel.h>

template< class T >
class os_sentinel

Interface

Constructor
os_sentinel( T& object )
Constructs a sentinel to guard access to object .

Throws: os_thread_toolkit_error

*
const T& operator*() const
Returns a constant reference to the guarded object.
*
T& operator*()
Returns a reference to the guarded object.
->
const T* operator->() const
Returns a constant pointer to the guarded object.
->
T* operator->()
Returns a pointer to the guarded object.
lock
void lock()
Acquires the lock, blocking if necessary. Depending upon the underlying platform, the lock attempt will fail or the thread will deadlock if it tries to obtain a mutex that it already owns.

Throws: os_thread_toolkit_error

notify
void notify()
Signals a change in the state of the guarded object, awakening all waiting threads. Calling notify() has no effect if there are no threads waiting. The calling thread must own the lock associated with the sentinel 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 lock.

Throws: os_thread_toolkit_error

notify_unlock
void notify_unlock()
Performs the same function as notify() , but then releases the lock afterwards.

Throws: os_thread_toolkit_error

observe
void observe()
Blocks until the guarded object is modified.

Throws: os_thread_toolkit_error

try_lock
bool try_lock()
Attempts to acquire the lock. Instead of blocking, this function returns false if it fails to acquire a lock immediately.

Throws: os_thread_toolkit_error

unlock
void unlock()
Releases the lock.

Throws: os_thread_toolkit_error

wait
void wait()
Synonym for observe() ; alternative event syntax.

Throws: os_thread_toolkit_error


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