MLIB
Loading...
Searching...
No Matches
mlib::lock Class Reference

Automatic wrapper for critical sections. More...

#include <critsect.h>

Public Member Functions

 lock (criticalsection &cs)
 Acquire critical section.
 
 lock (const lock &t)
 Copy constructor.
 
 ~lock ()
 Leave critical section.
 

Detailed Description

Automatic wrapper for critical sections.

Used in conjunction with criticalsection objects, locks simplify critical sections' management by taking advantage the automatic destruction of static objects in C++.

Use it as in example below:

criticalsection section; //Initialize critical section object
void func()
{
lock inuse( section ); //Acquire critical section
//... code protected by critical section
}//Here destructor for lock is invoked and critical section is released.
Lightweight inter-thread synchronization.
Definition critsect.h:25
Automatic wrapper for critical sections.
Definition critsect.h:69

The main advantage however is that any exception thrown inside func or any called function will also invoke the destructor for lock thus releasing the critical section.


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