nn::os::Mutex Class

Header file: nn/os.h

Syntax

class Mutex : public nn::os::WaitObject

Description

Class for handling mutexes. Mutexes are synchronization objects used for providing mutual exclusion.

Generally, use the nn::os::Mutex class instead of nn::os::CriticalSection. The nn::os::CriticalSection class performs considerably faster than nn::os::Mutex when there are no lock collisions between threads.

This mechanism prevents certain areas within programs from being run simultaneously within multiple threads. It also prevents data, registers, and other resources from being accessed by multiple threads simultaneously.

Mutexes can be locked using Lock. A mutex that is locked by a certain thread cannot be locked by other threads. If another thread attempts to lock it, that thread will block until the mutex is unlocked.

The Unlock method unlocks mutexes, but it can only be called from the locking thread because mutex locks are associated with their threads.

The Mutex class implements recursively locking mutexes. (In other words, Lock can be called from a locked thread.) In this case, the mutex will not be unlocked until Unlock is called the same number of times that Lock was called.

The Mutex class implements priority inheritance. If a high-priority thread ("H") attempts to get a lock on a mutex that is already locked by a low-priority thread ("L"), the priority of thread L will temporarily be raised to the same priority as thread H.

The Wait operation of a Mutex object gets a lock. Once the lock can be obtained, the Wait operation is released.

The use of nn::os::Mutex::ScopedLock makes it possible to lock a mutex starting when an object is created, and continuing until it goes out of scope.

Classes

nn::os::Mutex::ScopedLock Locks a mutex starting when an object is created, and continues locking it until the the object goes out of scope.

Member Functions

Mutex Constructs and initializes a mutex.
Initialize Initializes a mutex.
TryInitialize Tries to initialize a mutex.
Finalize Destroys a mutex.
~Mutex Destructor.
Lock Locks a mutex.
TryLock Tries to lock a mutex.
Unlock Unlocks a mutex.

Class Hierarchy

ADLFireWall::NonCopyable
  nn::os::HandleObject
    nn::os::WaitObject
      nn::os::Mutex

Revision History

2010/01/07
Initial version.

CONFIDENTIAL