Documentation Home >> Headers >> <mutex> Header >> std::timed_mutex class

The std::timed_mutex class provides support for locks with timeouts on top of the basic mutual exclusion and synchronization facility provided by std::mutex. Prior to accessing the data protected by the mutex, the mutex must be locked by calling lock(), try_lock(), try_lock_for() or try_lock_until(). If a lock is already held by another thread then an attempt to acquire the lock will fail (try_lock()), block until the lock can be acquired (lock()), or block until the lock can be acquired or the lock attempt times out (try_lock_for() or try_lock_until()). Once a lock has been acquired (whichever function was used to acquire it) it must be released by calling unlock() before another thread can acquire the lock on the mutex.

std::timed_mutex meets the TimedLockable requirements.

For details on the members, see std::timed_mutex class members.

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


    void lock();
    void unlock();
    bool try_lock();

    template<typename Rep,typename Period>
    bool try_lock_for(
        std::chrono::duration<Rep,Period> const&

    template<typename Clock,typename Duration>
    bool try_lock_until(
        std::chrono::time_point<Clock,Duration> const&

#include <mutex>

See Also