nn::os::CriticalSection Class

Header file: nn/os.h

Syntax

class CriticalSection : private ADLFireWall::NonCopyable

Description

Class for handling critical sections. Critical sections are synchronization objects used for providing mutual exclusion.

This mechanism prevents certain areas within programs from being run simultaneously within multiple threads. It also prevents resources from being accessed by multiple threads simultaneously.

Critical sections play the same role as mutexes (nn::os::Mutex), but they have the following limitations.

They can be used only to provide mutual exclusion within a single application. No priority inheritance takes place. Problems such as priority inversion may occur.Critical sections use more memory to store objects than mutexes do. The nn::os::CriticalSection class performs considerably faster than nn::os::Mutex when there are no lock collisions between threads. In most cases, use nn::os::CriticalSection instead of nn::os::Mutex.

The use of nn::os::CriticalSection::ScopedLock makes it possible to enter a critical section when an object is created and stay in the critical section until the scope is exited.

Classes

nn::os::CriticalSection::ScopedLock Enters a critical section when an object is created and stays in until the scope is exited.

Member Functions

CriticalSection Constructs an object.
Initialize Initializes an object.
TryInitialize Tries to initialize an object.
Finalize Destroys a critical section.
~CriticalSection Destructor.
Enter Locks out other threads and prevents them from entering a critical section. This function blocks.
TryEnter Locks out other threads and prevents them from entering a critical section. This function does not block.
Leave Unlocks and allows other threads to enter a critical section.

Class Hierarchy

ADLFireWall::NonCopyable
  nn::os::CriticalSection

Revision History

2010/01/07
Initial version.

CONFIDENTIAL