Skip to content

timed_semaphore try_acquire_for

Alairion edited this page May 8, 2021 · 4 revisions

nes::timed_semaphore::try_acquire_for

Functions

    template<typename Rep, typename Period>
(1) bool try_acquire_for(const std::chrono::duration<Rep, Period>& timeout);
  1. Checks if a resource is available within a certain delay, and if that is the case decrements the resource counter.

Parameters

Name Description
timeout The maximum duration to wait for. Note that it is just a request and the implementation can wait for more than the specified time, especially for value smaller than 1 millisecond.

Return value

  1. Returns true if the resource counter was successfully decremented, returns false otherwise.

Exceptions

  1. May throw an exception depending on the implementation behaviour.

Implementation details

  1. On Windows, calls WaitForSingleObject
    On Posix systems, calls sem_timedwait
Clone this wiki locally