SimGrid
3.18
Versatile Simulation of Distributed Systems
|
A classical mutex, but blocking in the simulation world
It is strictly impossible to use a real mutex, such as std::mutex or pthread_mutex_t, because it would block the whole simulation.
Instead, you should use the present class, that is a drop-in replacement of <a href="http://en.cppreference.com/w/cpp/thread/mutex>std::mutex.
As for any S4U object, Mutexes are using the RAII idiom for memory management. Use createMutex() to get a MutexPtr to a newly created mutex and only manipulate MutexPtr.
#include <Mutex.hpp>
Public Types | |
using | Ptr = boost::intrusive_ptr< Mutex > |
Public Member Functions | |
Mutex (Mutex const &)=delete | |
You cannot create a new mutex by copying an existing one. More... | |
Mutex & | operator= (Mutex const &)=delete |
You cannot create a new mutex by value assignment either. More... | |
void | lock () |
Blocks the calling actor until the mutex can be obtained. More... | |
void | unlock () |
Release the ownership of the mutex, unleashing a blocked actor (if any) More... | |
bool | try_lock () |
Acquire the mutex if it's free, and return false (without blocking) if not. More... | |
Static Public Member Functions | |
static Ptr | createMutex () |
Constructs a new mutex. More... | |
Friends | |
void | intrusive_ptr_add_ref (Mutex *mutex) |
void | intrusive_ptr_release (Mutex *mutex) |
using simgrid::s4u::Mutex::Ptr = boost::intrusive_ptr<Mutex> |
|
delete |
You cannot create a new mutex by copying an existing one.
Use MutexPtr instead
You cannot create a new mutex by value assignment either.
Use MutexPtr instead
|
static |
Constructs a new mutex.
Create a new mutex.
void simgrid::s4u::Mutex::lock | ( | ) |
Blocks the calling actor until the mutex can be obtained.
void simgrid::s4u::Mutex::unlock | ( | ) |
Release the ownership of the mutex, unleashing a blocked actor (if any)
Will fail if the calling actor does not own the mutex.
bool simgrid::s4u::Mutex::try_lock | ( | ) |
Acquire the mutex if it's free, and return false (without blocking) if not.