critical_section


A simple, highly-efficient synchronization object used to guard resources in a multithreaded environment. A critical section supports recursive acquisition by the same thread, and must be unlocked as many times as it was locked before another thread can acquire it.

Library

Thread<ToolKit>

Declaration

#include <ospace/thread/critical.h>

class os_critical_section

Interface

Constructor
os_critical_section( bool locked )
Constructs a critical section with an initial locked (default false ) state.

Throws: os_thread_toolkit_error

Destructor
~ os_critical_section()
Destroys the critical section.
lock
void lock()
Acquires a lock, blocking if necessary. Multiple locks can be obtained by a thread.

Throws: os_thread_toolkit_error

obtain
void obtain()
Synonym for lock() ; alternative acquisition syntax.

Throws: os_thread_toolkit_error

release
void release()
Synonym for unlock() ; alternative acquisition syntax.

Throws: os_thread_toolkit_error

unlock
void unlock()
Releases a single lock. If a thread owns multiple locks, then an equal number of unlocks must occur before the critical section becomes available.

Throws: os_thread_toolkit_error


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