Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::timed_mutex::try_lock_until

      From cppreference.com
      <cpp‎ |thread‎ |timed mutex

      [edit template]
       
       
      Concurrency support library
      Threads
      (C++11)
      (C++20)
      this_thread namespace
      (C++11)
      (C++11)
      (C++11)
      Cooperative cancellation
      Mutual exclusion
      Generic lock management
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      Condition variables
      (C++11)
      Semaphores
      Latches and Barriers
      (C++20)
      (C++20)
      Futures
      (C++11)
      (C++11)
      (C++11)
      Safe reclamation
      Hazard pointers
      Atomic types
      (C++11)
      (C++20)
      Initialization of atomic types
      (C++11)(deprecated in C++20)
      (C++11)(deprecated in C++20)
      Memory ordering
      (C++11)(deprecated in C++26)
      Free functions for atomic operations
      Free functions for atomic flags
       
       
      template<class Clock,class Duration>
      bool try_lock_until(conststd::chrono::time_point<Clock, Duration>& timeout_time);
      (since C++11)

      Tries to lock the mutex. Blocks until specifiedtimeout_time has been reached (timeout) or the lock is acquired (owns the mutex), whichever comes first. On successful lock acquisition returnstrue, otherwise returnsfalse.

      Iftimeout_time has already passed, this function behaves liketry_lock().

      Clock must meet theClock requirements. The program is ill-formed ifstd::chrono::is_clock_v<Clock> isfalse.(since C++20)

      The standard recommends that the clock tied totimeout_time be used, in which case adjustments of the clock may be taken into account. Thus, the duration of the block might be more or less thantimeout_time- Clock::now() at the time of the call, depending on the direction of the adjustment and whether it is honored by the implementation. The function also may block until aftertimeout_time has been reached due to process scheduling or resource contention delays.

      As withtry_lock(), this function is allowed to fail spuriously and returnfalse even if the mutex was not locked by any other thread at some point beforetimeout_time.

      Priorunlock() operation on the same mutexsynchronizes-with (as defined instd::memory_order) this operation if it returnstrue.

      Iftry_lock_until is called by a thread that already owns the mutex, the behavior is undefined.

      Contents

      [edit]Parameters

      timeout_time - maximum time point to block until

      [edit]Return value

      true if the lock was acquired successfully, otherwisefalse.

      [edit]Exceptions

      Any exception thrown bytimeout_time (clocks, time points, and durations provided by the standard library never throw).

      [edit]Example

      This section is incomplete
      Reason: no example

      Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2093C++11try_lock_until threw nothingthrows timeout-related exceptions

      [edit]See also

      locks the mutex, blocks if the mutex is not available
      (public member function)[edit]
      tries to lock the mutex, returns if the mutex is not available
      (public member function)[edit]
      tries to lock the mutex, returns if the mutex has been
      unavailable for the specified timeout duration
      (public member function)[edit]
      unlocks the mutex
      (public member function)[edit]
      C documentation formtx_timedlock
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/thread/timed_mutex/try_lock_until&oldid=131445"

      [8]ページ先頭

      ©2009-2025 Movatter.jp