Skip to content

timed_named_mutex try_lock_for

Alairion edited this page May 8, 2021 · 4 revisions

nes::timed_named_mutex::try_lock_until

Functions

    template<class Rep, class Period>
(1) bool try_lock_for(const std::chrono::duration<Rep, Period>& timeout);
  1. Tries to lock the mutex. Blocks until specified timeout has elapsed or the lock is acquired.

Parameters

Name Description
timeout A std::chrono::duration representing the minimum time to wait for

Return value

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

Preconditions

  1. The calling thread must not own the mutex.

Exceptions

  1. Throws a std::runtime_error if the lock operation fails.

Implementation details

  1. On Windows, calls WaitForSingleObject with a timeout equal to the conversion of the duration to milliseconds (rounded down)
    On Posix systems, calls pthread_mutex_timedlock
Clone this wiki locally