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

A shared mutex that can be used to synchronize access to shared resources. The mutex can be acquired in exclusive (writer) mode (lock) or shared (reader) mode (lock_shared). The mutex is non-recursive and provides no fairness guarantees. More...

#include <coopsync_tbb/shared_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

 shared_mutex ()=default
 Constructs a new shared_mutex. The shared_mutex is initially unlocked.
 shared_mutex (const shared_mutex &)=delete
 The shared_mutex is not copy-constructible.
shared_mutex & operator= (const shared_mutex &)=delete
 The shared_mutex is not copy-assignable.
 shared_mutex (shared_mutex &&)=delete
 The shared_mutex is not move-constructible.
shared_mutex & operator= (shared_mutex &&)=delete
 shared_mutex is not move-assignable.
 ~shared_mutex ()
 Destroys the shared_mutex.
bool try_lock () noexcept
 Attempts to acquire the shared_mutex without suspending.
void lock ()
 Acquires the shared_mutex, suspending the calling task if necessary until the shared_mutex becomes available.
void unlock ()
 Releases the shared_mutex. If there are tasks suspended on the shared_mutex, either one of the exclusive waiters is resumed and acquires the shared_mutex, or a batch of shared waiters is resumed and acquires the shared_mutex.
bool try_lock_shared () noexcept
 Attempts to acquire the shared_mutex in a shared mode without suspending.
void lock_shared ()
 Acquires the shared_mutex in a shared mode, suspending the calling task if necessary until the shared_mutex becomes available in shared mode.
void unlock_shared ()
 Releases the shared_mutex from a shared mode. If there are tasks suspended on the shared_mutex, either one of the exclusive waiters is resumed and acquires the shared_mutex, or a batch of shared waiters is resumed and acquires the shared_mutex.

Static Public Attributes

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

Detailed Description

A shared mutex that can be used to synchronize access to shared resources. The mutex can be acquired in exclusive (writer) mode (lock) or shared (reader) mode (lock_shared). The mutex is non-recursive and provides no fairness guarantees.

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

◆ ~shared_mutex()

coopsync_tbb::shared_mutex::~shared_mutex ( )

Destroys the shared_mutex.

Note
The destructor must not be called while the shared_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::shared_mutex::lock ( )

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

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

◆ lock_shared()

void coopsync_tbb::shared_mutex::lock_shared ( )

Acquires the shared_mutex in a shared mode, suspending the calling task if necessary until the shared_mutex becomes available in shared mode.

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

◆ try_lock()

bool coopsync_tbb::shared_mutex::try_lock ( )
nodiscardnoexcept

Attempts to acquire the shared_mutex without suspending.

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

◆ try_lock_shared()

bool coopsync_tbb::shared_mutex::try_lock_shared ( )
nodiscardnoexcept

Attempts to acquire the shared_mutex in a shared mode without suspending.

Returns
true if the shared_mutex was successfully acquired in shared mode, false otherwise.

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