CoopSync for TBB 0.1.0
Cooperative synchronization primitives for TBB resumable tasks
Loading...
Searching...
No Matches
coopsync_tbb::mutex Class Reference

A mutex that can be used to synchronize access to shared resources. The mutex is non-recursive and provides no fairness guarantees. An attempt to acquire a mutex that is already in acquired state suspends the calling task until the mutex can be acquired. More...

#include <coopsync_tbb/mutex.hpp>

Classes

class  scoped_lock
 RAII wrapper for mutex that acquires the mutex on construction and releases it on destruction. More...

Public Member Functions

 mutex ()=default
 Constructs a new mutex. The mutex is initially unlocked.
 mutex (const mutex &)=delete
 The mutex is not copy-constructible.
mutex & operator= (const mutex &)=delete
 The mutex is not copy-assignable.
 mutex (mutex &&)=delete
 The mutex is not move-constructible.
mutex & operator= (mutex &&)=delete
 Mutex is not move-assignable.
 ~mutex ()
 Destroys the mutex.
bool try_lock () noexcept
 Attempts to acquire the mutex without suspending.
void lock ()
 Acquires the mutex, suspending the calling task if necessary until the mutex becomes available.
void unlock ()
 Releases the mutex. If there are tasks suspended on the mutex, exactly one of them is resumed and acquires the mutex.

Static Public Attributes

static constexpr bool is_rw_mutex = false
 The mutex is not a reader-writer (shared) mutex.
static constexpr bool is_recursive_mutex = false
 The mutex is not recursive.
static constexpr bool is_fair_mutex = false
 The mutex does not provide any fairness guarantees.

Detailed Description

A mutex that can be used to synchronize access to shared resources. The mutex is non-recursive and provides no fairness guarantees. An attempt to acquire a mutex that is already in acquired state suspends the calling task until the mutex can be acquired.

Note
This mutex does satisfy the standard named requirements for BasicLockable and Lockable but does not meet the requirements for Mutex because it never blocks the calling thread, even though it exposes the same interface. Concurrent invocations of the member functions, except for destructor, are safe.

Constructor & Destructor Documentation

◆ ~mutex()

coopsync_tbb::mutex::~mutex ( )

Destroys the mutex.

Note
The destructor must not be called while the mutex is still locked or while there are tasks suspended on it. The destructor does not notify or resume any waiting tasks.

Member Function Documentation

◆ lock()

void coopsync_tbb::mutex::lock ( )

Acquires the mutex, suspending the calling task if necessary until the mutex becomes available.

Note
The suspended task must remain valid until it is resumed.
The suspended task must be resumed before the mutex is destroyed.

◆ try_lock()

bool coopsync_tbb::mutex::try_lock ( )
nodiscardnoexcept

Attempts to acquire the mutex without suspending.

Returns
true if the mutex was successfully acquired, false otherwise.

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