30 Thread support library [thread]

30.4 Mutual exclusion [thread.mutex]

30.4.1 Mutex requirements [thread.mutex.requirements]

30.4.1.3 Timed mutex types [thread.timedmutex.requirements]

30.4.1.3.1 Class timed_mutex [thread.timedmutex.class]

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

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

    void lock();  // blocking
    bool try_lock();
    template <class Rep, class Period>
      bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
    template <class Clock, class Duration>
      bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
    void unlock();

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

The class timed_mutex provides a non-recursive mutex with exclusive ownership semantics. If one thread owns a timed_mutex object, attempts by another thread to acquire ownership of that object will fail (for try_lock()) or block (for lock(), try_lock_for(), and try_lock_until()) until the owning thread has released ownership with a call to unlock() or the call to try_lock_for() or try_lock_until() times out (having failed to obtain ownership).

The class timed_mutex shall satisfy all of the TimedMutex requirements ([thread.timedmutex.requirements]). It shall be a standard-layout class (Clause [class]).

The behavior of a program is undefined if:

  • it destroys a timed_mutex object owned by any thread,

  • a thread that owns a timed_mutex object calls lock(), try_lock(), try_lock_for(), or try_lock_until() on that object, or

  • a thread terminates while owning a timed_mutex object.