Open CASCADE Technology Reference Manual 8.0.0
Loading...
Searching...
No Matches
Functions | Variables
Standard_Mutex.hxx File Reference
#include <Standard_Integer.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Macro.hxx>
#include <NCollection_Shared.hxx>
#include <pthread.h>
#include <unistd.h>
#include <time.h>

Functions

 Sentry (Standard_Mutex *theMutex)
 Constructor - initializes the sentry object by pointer to a mutex and locks the mutex if its pointer is not NULL.
 
 ~Sentry ()
 Destructor - unlocks the mutex if already locked.
 
 ~Standard_Mutex () override
 Destructor: destroys the mutex object.
 
bool TryLock ()
 Method to test the mutex; if the mutex is not hold by other thread, locks it and returns True; otherwise returns False without waiting mutex to be released.
 

Variables

class Standard_Mutex is deprecated
 Mutex: a class to synchronize access to shared data.
 
use std::mutex instead Will be removed in OCCT Standard_Mutex ()
 Constructor: creates a mutex object and initializes it. It is strongly recommended that mutexes were created as static objects whenever possible.
 

Function Documentation

◆ Sentry()

Sentry ( Standard_Mutex * theMutex)

Constructor - initializes the sentry object by pointer to a mutex and locks the mutex if its pointer is not NULL.

◆ TryLock()

bool TryLock ( )

Method to test the mutex; if the mutex is not hold by other thread, locks it and returns True; otherwise returns False without waiting mutex to be released.

◆ ~Sentry()

~Sentry ( )

Destructor - unlocks the mutex if already locked.

◆ ~Standard_Mutex()

~Standard_Mutex ( )
override

Destructor: destroys the mutex object.

Variable Documentation

◆ deprecated

class Standard_Mutex is deprecated

Mutex: a class to synchronize access to shared data.

Deprecated
This class is deprecated and will be removed in OCCT 8.0.0. Use std::mutex or std::shared_mutex directly instead.

This is simple encapsulation of tools provided by the operating system to synchronize access to shared data from threads within one process.

Current implementation is very simple and straightforward; it is just a wrapper around POSIX pthread library on UNIX/Linux, and CRITICAL_SECTIONs on Windows NT. It does not provide any advanced functionality such as recursive calls to the same mutex from within one thread (such call will freeze the execution).

Note that all the methods of that class are made inline, in order to keep maximal performance. This means that a library using the mutex might need to be linked to threads library directly.

The typical use of this class should be as follows:

  • create instance of the class Standard_Mutex in the global scope (whenever possible, or as a field of your class)
  • create instance of class Standard_Mutex::Sentry using that Mutex when entering critical section

Note that this class provides one feature specific to Open CASCADE: safe unlocking the mutex when signal is raised and converted to OCC exceptions (Note that with current implementation of this functionality on UNIX and Linux, C longjumps are used for that, thus destructors of classes are not called automatically).

To use this feature, call RegisterCallback() after Lock() or successful TryLock(), and UnregisterCallback() before Unlock() (or use Sentry classes).

◆ Standard_Mutex

Standard_Mutex

Constructor: creates a mutex object and initializes it. It is strongly recommended that mutexes were created as static objects whenever possible.