DASH  0.3.0
dash::Mutex Class Reference

Behaves similar to std::mutex and is used to ensure mutual exclusion within a dash team. More...

#include <Mutex.h>

Public Member Functions

 Mutex (Team &team=dash::Team::All())
 DASH Mutex is only valid for a dash team. More...
 
 Mutex (const Mutex &other)=delete
 
 Mutex (Mutex &&other)=default
 
self_toperator= (const self_t &other)=delete
 
self_toperator= (self_t &&other)=default
 
 ~Mutex ()=default
 Collective destructor to destruct a DART lock. More...
 
bool init ()
 Collective initialization of the DART lock. More...
 
void lock ()
 Block until the lock was acquired. More...
 
bool try_lock ()
 Try to acquire the lock and return immediately. More...
 
void unlock ()
 Release the lock acquired through lock() or try_lock(). More...
 

Detailed Description

Behaves similar to std::mutex and is used to ensure mutual exclusion within a dash team.

Note
This works properly with std::lock_guard
Mutex cannot be placed in DASH containers
// just for demonstration, better use atomic operations
dash::Mutex mx; // mutex for dash::Team::All();
{
std::lock_guard<dash::Mutex> lg(mx);
int tmp = arr[0];
arr[0] = tmp + 1;
// TODO: this almost certainly requires a flush
}
// postcondition: arr[0] == dash::size();

Definition at line 30 of file Mutex.h.

Constructor & Destructor Documentation

◆ Mutex()

dash::Mutex::Mutex ( Team team = dash::Team::All())
explicit

DASH Mutex is only valid for a dash team.

If no team is passed, team all is used.

This function is not thread-safe

Parameters
teamteam for mutual exclusive accesses

◆ ~Mutex()

dash::Mutex::~Mutex ( )
default

Collective destructor to destruct a DART lock.

This function is not thread-safe

Member Function Documentation

◆ init()

bool dash::Mutex::init ( )

Collective initialization of the DART lock.

This function is not thread-safe

Returns
True if lock was successfully initialized, False otherwise

◆ lock()

void dash::Mutex::lock ( )

Block until the lock was acquired.

◆ try_lock()

bool dash::Mutex::try_lock ( )

Try to acquire the lock and return immediately.

Returns
True if lock was successfully aquired, False otherwise

◆ unlock()

void dash::Mutex::unlock ( )

Release the lock acquired through lock() or try_lock().


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