PIP 5.5.3
Platform-Independent Primitives
Public Member Functions | List of all members
PIMutex Class Reference

Simple mutex. More...

#include <pimutex.h>

Public Member Functions

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

Detailed Description

Simple mutex.

Synopsis

PIMutex provides critical code section defence 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().

For automatic lock-unlock use PIMutexLocker.

Usage

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

// critical section start
mutex.lock();
// ... your code here
mutex.unlock();
// critical section end

Member Function Documentation

◆ lock()

void PIMutex::lock ( )

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

◆ unlock()

void PIMutex::unlock ( )

Unlock mutex.

In any case this function returns immediate

◆ tryLock()

bool PIMutex::tryLock ( )

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"