PIP  0.4.0_beta2
Platform-Independent Primitives
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PIMutex Class Reference

Mutex. More...

Public Member Functions

 PIMutex ()
 Constructs unlocked mutex.
 
void lock ()
 Lock mutex. More...
 
void unlock ()
 Unlock mutex. More...
 
bool tryLock ()
 Try to lock mutex. More...
 

Detailed Description

Mutex.

Synopsis

PIMutex provides synchronization blocks between several threads. Using mutex guarantees execution of some code only one of threads. Mutex contains logic state and functions to change it: lock(), unlock() and tryLock().

Usage

Block of code that should to be executed only one thread simultaniously should to be started with lock() and ended with unlock().

mutex.lock();
// ... your code here
mutex.unlock();

"mutex" in this example is one for all threads.

Member Function Documentation

void PIMutex::lock ( )
inline

Lock mutex.

If mutex is unlocked it set to locked state and returns immediate. If mutex is already locked function blocks until mutex will be unlocked

void PIMutex::unlock ( )
inline

Unlock mutex.

In any case this function returns immediate

bool PIMutex::tryLock ( )
inline

Try to lock mutex.

If mutex is unlocked it set to locked state and returns "true" immediate. If mutex is already locked function returns immediate an returns "false"