30 Thread support library [thread]

30.4 Mutual exclusion [thread.mutex]

30.4.1 Mutex requirements [thread.mutex.requirements]

30.4.1.4 Shared mutex types [thread.sharedmutex.requirements]

30.4.1.4.1 Class shared_mutex [thread.sharedmutex.class]

namespace std {
  class shared_mutex {
  public:
     shared_mutex();
     ~shared_mutex();

     shared_mutex(const shared_mutex&) = delete;
     shared_mutex& operator=(const shared_mutex&) = delete;

     // Exclusive ownership
     void lock(); // blocking
     bool try_lock();
     void unlock();

     // Shared ownership
     void lock_shared(); // blocking
     bool try_lock_shared();
     void unlock_shared();

     using native_handle_type = implementation-defined; // See [thread.req.native]
     native_handle_type native_handle();                // See [thread.req.native]
  };
}

The class shared_mutex provides a non-recursive mutex with shared ownership semantics.

The class shared_mutex shall satisfy all of the shared mutex requirements ([thread.sharedmutex.requirements]). It shall be a standard-layout class (Clause [class]).

The behavior of a program is undefined if:

  • it destroys a shared_mutex object owned by any thread,

  • a thread attempts to recursively gain any ownership of a shared_mutex, or

  • a thread terminates while possessing any ownership of a shared_mutex.

shared_mutex may be a synonym for shared_timed_mutex.