In this description,
m denotes an object of a shared timed mutex type,
rel_time denotes an object of an instantiation of
duration (
[time.duration]), and
abs_time denotes an object of an instantiation of
time_point. The expression m.try_lock_shared_for(rel_time) is well-formed and
has the following semantics:
Effects: Attempts to obtain
shared lock ownership for the calling thread within the relative
timeout (
[thread.req.timing]) specified by
rel_time. If the time
specified by
rel_time is less than or equal to
rel_time.zero(),
the function attempts to obtain ownership without blocking (as if by calling
try_lock_shared())
. The function returns within the timeout
specified by
rel_time only if it has obtained shared ownership of the
mutex object
. [
Note 2:
As with
try_lock(), there is no guarantee that
ownership will be obtained if the lock is available, but implementations are
expected to make a strong effort to do so
. —
end note]
If an exception is thrown then a shared lock has not been acquired for
the current thread
.Synchronization: If
try_lock_shared_for() returns
true, prior
unlock() operations on the same object synchronize
with (
[intro.multithread]) this operation
. The expression m.try_lock_shared_until(abs_time) is well-formed
and has the following semantics:
Effects: The function attempts to obtain shared ownership of the mutex
. If
abs_time has already passed, the function attempts to obtain shared
ownership without blocking (as if by calling
try_lock_shared())
. The
function returns before the absolute timeout (
[thread.req.timing])
specified by
abs_time only if it has obtained shared ownership of the
mutex object
. [
Note 3:
As with
try_lock(), there is no guarantee that
ownership will be obtained if the lock is available, but implementations are
expected to make a strong effort to do so
. —
end note]
If an exception is thrown then a shared lock has not been acquired for
the current thread
.Synchronization: If
try_lock_shared_until() returns
true, prior
unlock() operations on the same object synchronize
with (
[intro.multithread]) this operation
. namespace std {
class shared_timed_mutex {
public:
shared_timed_mutex();
~shared_timed_mutex();
shared_timed_mutex(const shared_timed_mutex&) = delete;
shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;
void lock();
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();
void lock_shared();
bool try_lock_shared();
template<class Rep, class Period>
bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
template<class Clock, class Duration>
bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
void unlock_shared();
};
}
The class
shared_timed_mutex provides a non-recursive mutex with shared
ownership semantics
.The class
shared_timed_mutex meets
all of the shared timed mutex requirements ([thread.
sharedtimedmutex.
requirements])
. The behavior of a program is undefined if
- it destroys a shared_timed_mutex object owned by any thread,
- a thread attempts to recursively gain any ownership of a shared_timed_mutex, or
- a thread terminates while possessing any ownership of a shared_timed_mutex.