libcommonc++  0.7
CriticalSection Class Reference

A critical section, a synchronization primitive that is typically more efficient than but roughly semantically equivalent to a Mutex. More...

#include <CriticalSection.h++>

Inheritance diagram for CriticalSection:
Collaboration diagram for CriticalSection:

Public Member Functions

 CriticalSection ()
 Constructor. More...
 
 ~CriticalSection ()
 Destructor. More...
 
void enter ()
 Enter the critical section, blocking if necessary. More...
 
void lock ()
 Equivalent to enter(). More...
 
bool tryEnter ()
 Try to enter the critical section, returning immediately if it could not be entered. More...
 
void leave ()
 Leave the critical section. More...
 
void unlock ()
 Equivalent to leave(). More...
 

Detailed Description

A critical section, a synchronization primitive that is typically more efficient than but roughly semantically equivalent to a Mutex.

Only one thread may be "within" a CriticalSection at any one time.

CriticalSections are recursive, so a thread may re-enter a CriticalSection that it has already entered. However, the thread must leave the CriticalSection the same number of times that it has entered it in order to release it.

See also ScopedLock.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ CriticalSection()

Constructor.

◆ ~CriticalSection()

Destructor.

It is the calling code's responsibility to ensure that a CriticalSection is deleted only when no thread is within it.

Member Function Documentation

◆ enter()

void enter ( )

Enter the critical section, blocking if necessary.

◆ leave()

void leave ( )

Leave the critical section.

◆ lock()

void lock ( )
inlinevirtual

Equivalent to enter().

Implements Lock.

◆ tryEnter()

bool tryEnter ( )

Try to enter the critical section, returning immediately if it could not be entered.

Returns
true if the critical section was entered, false otherwise.

◆ unlock()

void unlock ( )
inlinevirtual

Equivalent to leave().

Implements Lock.


The documentation for this class was generated from the following files: