SimGrid  3.16
Versatile Simulation of Distributed Systems
simgrid::s4u::Mutex Class Reference

Detailed Description

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...
 
Mutexoperator= (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)
 

Member Typedef Documentation

◆ Ptr

using simgrid::s4u::Mutex::Ptr = boost::intrusive_ptr<Mutex>

Constructor & Destructor Documentation

◆ Mutex()

simgrid::s4u::Mutex::Mutex ( Mutex const &  )
delete

You cannot create a new mutex by copying an existing one.

Use MutexPtr instead

Member Function Documentation

◆ operator=()

Mutex& simgrid::s4u::Mutex::operator= ( Mutex const &  )
delete

You cannot create a new mutex by value assignment either.

Use MutexPtr instead

◆ createMutex()

MutexPtr simgrid::s4u::Mutex::createMutex ( )
static

◆ lock()

void simgrid::s4u::Mutex::lock ( )

Blocks the calling actor until the mutex can be obtained.

◆ unlock()

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.

◆ try_lock()

bool simgrid::s4u::Mutex::try_lock ( )

Acquire the mutex if it's free, and return false (without blocking) if not.

Friends And Related Function Documentation

◆ intrusive_ptr_add_ref

void intrusive_ptr_add_ref ( Mutex mutex)
friend

◆ intrusive_ptr_release

void intrusive_ptr_release ( Mutex mutex)
friend

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