synchronization¶
See Public API for a list of names and headers that are part of the public HPX API.
-
namespace
hpx
-
namespace
experimental
-
template<typename
ReadWriteT
, typenameReadT
, typenameAllocator
>
classasync_rw_mutex
¶ - #include <async_rw_mutex.hpp>
Read-write mutex where access is granted to a value through senders.
The wrapped value is accessed through read and readwrite, both of which return senders which call set_value on a connected receiver when the wrapped value is safe to read or write. The senders send the value through a wrapper type which is implicitly convertible to a reference of the wrapped value. Read-only senders send wrappers that are convertible to const references.
A read-write sender gives exclusive access to the wrapped value, while a read-only sender gives shared (with other read-only senders) access to the value.
A void mutex acts as a mutex around some user-managed resource, i.e. the void mutex does not manage any value and the types sent by the senders are not convertible. The sent types are copyable and release access to the protected resource when released.
The order in which senders call set_value is determined by the order in which the senders are retrieved from the mutex. Connecting and starting the senders is thread-safe.
Retrieving senders from the mutex is not thread-safe.
The mutex is movable and non-copyable.
Public Types
-
template<>
usingvalue_type
= readwrite_type¶
-
template<>
usingread_access_type
= detail::async_rw_mutex_access_wrapper<readwrite_type, read_type, detail::async_rw_mutex_access_type::read>¶
-
template<>
usingreadwrite_access_type
= detail::async_rw_mutex_access_wrapper<readwrite_type, read_type, detail::async_rw_mutex_access_type::readwrite>¶
-
template<>
usingallocator_type
= Allocator¶
Public Functions
-
async_rw_mutex
()¶
-
template<typename
U
, typename = std::enable_if_t<!std::is_same<std::decay_t<U>, async_rw_mutex>::value>>async_rw_mutex
(U &&u, allocator_type const &alloc = {})¶
-
async_rw_mutex
(async_rw_mutex&&)¶
-
async_rw_mutex &
operator=
(async_rw_mutex&&)¶
-
async_rw_mutex
(async_rw_mutex const&)¶
-
async_rw_mutex &
operator=
(async_rw_mutex const&)¶
-
sender<detail::async_rw_mutex_access_type::read>
read
()¶
-
sender<detail::async_rw_mutex_access_type::readwrite>
readwrite
()¶
Private Types
Private Members
-
value_type
value
¶
-
allocator_type
alloc
¶
-
detail::async_rw_mutex_access_type
prev_access
= detail::async_rw_mutex_access_type::readwrite¶
-
shared_state_ptr_type
prev_state
¶
-
shared_state_ptr_type
state
¶
-
template<detail::async_rw_mutex_access_type
AccessType
>
structsender
¶ Public Types
-
template<>
template<>
usingaccess_type
= detail::async_rw_mutex_access_wrapper<readwrite_type, read_type, AccessType>¶
Friends
-
template<typename
Env
>
autotag_invoke
(hpx::execution::experimental::get_completion_signatures_t, sender const&, Env)
-
template<typename
R
>
autotag_invoke
(hpx::execution::experimental::connect_t, sender &&s, R &&r)
-
template<typename
Env
>
structgenerate_completion_signatures
¶ Public Types
-
template<>
template<>
template<template<typename...> typenameTuple
, template<typename...> typenameVariant
>
usingvalue_types
= Variant<Tuple<access_type>>¶
Public Static Attributes
-
template<>
template<>
constexpr boolsends_stopped
= false¶
-
template<>
-
template<typename
R
>
structoperation_state
¶ Public Functions
-
template<>
template<>operation_state
(operation_state&&)¶
-
template<>
template<>
operation_state &operator=
(operation_state&&)¶
-
template<>
template<>operation_state
(operation_state const&)¶
-
template<>
template<>
operation_state &operator=
(operation_state const&)¶
Public Members
-
template<>
template<>
shared_state_ptr_typeprev_state
¶
-
template<>
template<>
shared_state_ptr_typestate
¶
Friends
-
void
tag_invoke
(hpx::execution::experimental::start_t, operation_state &os)
-
template<>
-
template<>
-
template<>
-
template<typename
Allocator
>
classasync_rw_mutex
<void, void, Allocator>¶ Public Types
-
template<>
usingread_type
= void¶
-
template<>
usingreadwrite_type
= void¶
-
template<>
usingread_access_type
= detail::async_rw_mutex_access_wrapper<readwrite_type, read_type, detail::async_rw_mutex_access_type::read>¶
-
template<>
usingreadwrite_access_type
= detail::async_rw_mutex_access_wrapper<readwrite_type, read_type, detail::async_rw_mutex_access_type::readwrite>¶
-
template<>
usingallocator_type
= Allocator¶
Public Functions
-
async_rw_mutex
(allocator_type const &alloc = {})¶
-
async_rw_mutex
(async_rw_mutex&&)
-
async_rw_mutex &
operator=
(async_rw_mutex&&)
-
async_rw_mutex
(async_rw_mutex const&)
-
async_rw_mutex &
operator=
(async_rw_mutex const&)
-
sender<detail::async_rw_mutex_access_type::read>
read
()
-
sender<detail::async_rw_mutex_access_type::readwrite>
readwrite
()
Private Types
Private Members
-
allocator_type
alloc
-
detail::async_rw_mutex_access_type
prev_access
= detail::async_rw_mutex_access_type::readwrite
-
shared_state_ptr_type
prev_state
-
shared_state_ptr_type
state
-
template<detail::async_rw_mutex_access_type
AccessType
>
structsender
¶ Public Types
-
template<>
template<>
usingaccess_type
= detail::async_rw_mutex_access_wrapper<readwrite_type, read_type, AccessType>¶
Friends
-
template<typename
Env
>
autotag_invoke
(hpx::execution::experimental::get_completion_signatures_t, sender const&, Env)
-
template<typename
R
>
autotag_invoke
(hpx::execution::experimental::connect_t, sender &&s, R &&r)
-
template<typename
Env
>
structgenerate_completion_signatures
¶ Public Types
-
template<>
template<>
template<template<typename...> typenameTuple
, template<typename...> typenameVariant
>
usingvalue_types
= Variant<Tuple<access_type>>¶
Public Static Attributes
-
template<>
template<>
constexpr boolsends_stopped
= false¶
-
template<>
-
template<typename
R
>
structoperation_state
¶ Public Functions
-
template<>
template<>operation_state
(operation_state&&)¶
-
template<>
template<>
operation_state &operator=
(operation_state&&)¶
-
template<>
template<>operation_state
(operation_state const&)¶
-
template<>
template<>
operation_state &operator=
(operation_state const&)¶
Public Members
-
template<>
template<>
shared_state_ptr_typeprev_state
¶
-
template<>
template<>
shared_state_ptr_typestate
¶
Friends
-
void
tag_invoke
(hpx::execution::experimental::start_t, operation_state &os)
-
template<>
-
template<>
-
template<>
-
template<typename
-
namespace
-
namespace
hpx
-
template<typename
OnCompletion
= detail::empty_oncompletion>
classbarrier
¶ - #include <barrier.hpp>
A barrier is a thread coordination mechanism whose lifetime consists of a sequence of barrier phases, where each phase allows at most an expected number of threads to block until the expected number of threads arrive at the barrier. [ Note: A barrier is useful for managing repeated tasks that are handled by multiple threads. - end note ] Each barrier phase consists of the following steps:
The expected count is decremented by each call to arrive or arrive_and_drop.
When the expected count reaches zero, the phase completion step is run. For the specialization with the default value of the CompletionFunction template parameter, the completion step is run as part of the call to arrive or arrive_and_drop that caused the expected count to reach zero. For other specializations, the completion step is run on one of the threads that arrived at the barrier during the phase.
When the completion step finishes, the expected count is reset to what was specified by the expected argument to the constructor, possibly adjusted by calls to arrive_and_drop, and the next phase starts.
Each phase defines a phase synchronization point. Threads that arrive at the barrier during the phase can block on the phase synchronization point by calling wait, and will remain blocked until the phase completion step is run. The phase completion step that is executed at the end of each phase has the following effects:
Invokes the completion function, equivalent to completion().
Unblocks all threads that are blocked on the phase synchronization point.
The end of the completion step strongly happens before the returns from all calls that were unblocked by the completion step. For specializations that do not have the default value of the CompletionFunction template parameter, the behavior is undefined if any of the barrier object’s member functions other than wait are called while the completion step is in progress.
Concurrent invocations of the member functions of barrier, other than its destructor, do not introduce data races. The member functions arrive and arrive_and_drop execute atomically.
CompletionFunction shall meet the Cpp17MoveConstructible (Table 28) and Cpp17Destructible (Table 32) requirements. std::is_nothrow_invocable_v<CompletionFunction&> shall be true.
The default value of the CompletionFunction template parameter is an unspecified type, such that, in addition to satisfying the requirements of CompletionFunction, it meets the Cpp17DefaultConstructible requirements (Table 27) and completion() has no effects.
barrier::arrival_token is an unspecified type, such that it meets the Cpp17MoveConstructible (Table 28), Cpp17MoveAssignable (Table 30), and Cpp17Destructible (Table 32) requirements.
Public Types
-
template<>
usingarrival_token
= bool¶
Public Functions
-
constexpr
barrier
(std::ptrdiff_t expected, OnCompletion completion = OnCompletion())¶ Preconditions: expected >= 0 is true and expected <= max() is true.
Effects: Sets both the initial expected count for each barrier phase and the current expected count for the first phase to expected. Initializes completion with std::move(f). Starts the first phase. [Note: If expected is 0 this object can only be destroyed.- end note]
- Exceptions
-
arrival_token
arrive
(std::ptrdiff_t update = 1)¶ Preconditions: update > 0 is true, and update is less than or equal to the expected count for the current barrier phase.
Effects: Constructs an object of type arrival_token that is associated with the phase synchronization point for the current phase. Then, decrements the expected count by update.
Synchronization: The call to arrive strongly happens before the start of the phase completion step for the current phase.
- Return
: The constructed arrival_token object.
- Exceptions
-
void
wait
(arrival_token &&old_phase) const¶ Preconditions: arrival is associated with the phase synchronization point for the current phase or the immediately preceding phase of the same barrier object.
Effects: Blocks at the synchronization point associated with HPX_MOVE(arrival) until the phase completion step of the synchronization point’s phase is run. [ Note: If arrival is associated with the synchronization point for a previous phase, the call returns immediately. - end note ]
- Exceptions
-
void
arrive_and_wait
()¶ Effects: Equivalent to: wait(arrive()).
-
void
arrive_and_drop
()¶ Preconditions: The expected count for the current barrier phase is greater than zero.
Effects: Decrements the initial expected count for all subsequent phases by one. Then decrements the expected count for the current phase by one.
Synchronization: The call to arrive_and_drop strongly happens before the start of the phase completion step for the current phase.
- Exceptions
Public Static Functions
-
static constexpr std::ptrdiff_t() hpx::barrier::max()
-
template<typename
-
namespace
hpx
-
namespace
lcos
-
namespace
local
-
-
template<typename
T
, typenameMutex
= util::spinlock>
classbounded_channel
¶ Public Functions
-
bounded_channel
(bounded_channel &&rhs)¶
-
bounded_channel &
operator=
(bounded_channel &&rhs)¶
-
~bounded_channel
()¶
-
bool
get
(T *val = nullptr) const¶
-
bool
set
(T &&t)¶
Private Types
-
template<>
usingmutex_type
= Mutex¶
-
-
template<typename
-
namespace
-
namespace
-
namespace
hpx
-
namespace
lcos
-
namespace
local
-
-
template<typename
T
, typenameMutex
= util::spinlock>
classbase_channel_mpsc
¶ Public Functions
-
base_channel_mpsc
(base_channel_mpsc &&rhs)¶
-
base_channel_mpsc &
operator=
(base_channel_mpsc &&rhs)¶
-
~base_channel_mpsc
()¶
-
bool
get
(T *val = nullptr) const¶
-
bool
set
(T &&t)¶
Private Types
-
template<>
usingmutex_type
= Mutex¶
Private Members
-
struct
tail_data
¶
-
-
template<typename
-
namespace
-
namespace
-
namespace
hpx
-
namespace
lcos
-
namespace
local
-
namespace
-
namespace
-
namespace
hpx
-
namespace
lcos
-
namespace
local
-
-
class
condition_variable
¶ Public Functions
-
condition_variable
()¶
-
~condition_variable
()¶
-
void
notify_one
(error_code &ec = throws)¶
-
void
notify_all
(error_code &ec = throws)¶
-
template<typename
Mutex
>
voidwait
(std::unique_lock<Mutex> &lock, error_code &ec = throws)¶
-
template<typename
Mutex
, typenamePredicate
>
voidwait
(std::unique_lock<Mutex> &lock, Predicate pred, error_code& = throws)¶
-
template<typename
Mutex
>
cv_statuswait_until
(std::unique_lock<Mutex> &lock, hpx::chrono::steady_time_point const &abs_time, error_code &ec = throws)¶
-
template<typename
Mutex
, typenamePredicate
>
boolwait_until
(std::unique_lock<Mutex> &lock, hpx::chrono::steady_time_point const &abs_time, Predicate pred, error_code &ec = throws)¶
-
template<typename
Mutex
>
cv_statuswait_for
(std::unique_lock<Mutex> &lock, hpx::chrono::steady_duration const &rel_time, error_code &ec = throws)¶
-
template<typename
Mutex
, typenamePredicate
>
boolwait_for
(std::unique_lock<Mutex> &lock, hpx::chrono::steady_duration const &rel_time, Predicate pred, error_code &ec = throws)¶
Private Types
-
using
mutex_type
= detail::condition_variable_data::mutex_type¶
-
-
class
condition_variable_any
¶ Public Functions
-
condition_variable_any
()¶
-
~condition_variable_any
()¶
-
void
notify_one
(error_code &ec = throws)¶
-
void
notify_all
(error_code &ec = throws)¶
-
template<typename
Lock
>
voidwait
(Lock &lock, error_code &ec = throws)¶
-
template<typename
Lock
, typenamePredicate
>
voidwait
(Lock &lock, Predicate pred, error_code& = throws)¶
-
template<typename
Lock
>
cv_statuswait_until
(Lock &lock, hpx::chrono::steady_time_point const &abs_time, error_code &ec = throws)¶
-
template<typename
Lock
, typenamePredicate
>
boolwait_until
(Lock &lock, hpx::chrono::steady_time_point const &abs_time, Predicate pred, error_code &ec = throws)¶
-
template<typename
Lock
>
cv_statuswait_for
(Lock &lock, hpx::chrono::steady_duration const &rel_time, error_code &ec = throws)¶
-
template<typename
Lock
, typenamePredicate
>
boolwait_for
(Lock &lock, hpx::chrono::steady_duration const &rel_time, Predicate pred, error_code &ec = throws)¶
-
template<typename
Lock
, typenamePredicate
>
boolwait
(Lock &lock, stop_token stoken, Predicate pred, error_code &ec = throws)¶
-
template<typename
Lock
, typenamePredicate
>
boolwait_until
(Lock &lock, stop_token stoken, hpx::chrono::steady_time_point const &abs_time, Predicate pred, error_code &ec = throws)¶
-
template<typename
Lock
, typenamePredicate
>
boolwait_for
(Lock &lock, stop_token stoken, hpx::chrono::steady_duration const &rel_time, Predicate pred, error_code &ec = throws)¶
Private Types
-
using
mutex_type
= detail::condition_variable_data::mutex_type¶
-
-
class
-
namespace
-
namespace
-
namespace
hpx
-
namespace
lcos
-
namespace
local
Typedefs
-
typedef counting_semaphore_var
counting_semaphore
¶
-
template<typename
Mutex
= hpx::lcos::local::spinlock, intN
= 0>
classcounting_semaphore_var
: private hpx::lcos::local::cpp20_counting_semaphore<PTRDIFF_MAX, hpx::lcos::local::spinlock>¶ Public Functions
-
counting_semaphore_var
(counting_semaphore_var const&)¶
-
counting_semaphore_var &
operator=
(counting_semaphore_var const&)¶
Private Types
-
template<>
usingmutex_type
= Mutex¶
-
-
template<typename
Mutex
= hpx::lcos::local::spinlock>
classcpp20_binary_semaphore
: public hpx::lcos::local::cpp20_counting_semaphore<1, hpx::lcos::local::spinlock>¶
-
template<std::ptrdiff_t
LeastMaxValue
= PTRDIFF_MAX, typenameMutex
= hpx::lcos::local::spinlock>
classcpp20_counting_semaphore
¶ Public Functions
-
HPX_NON_COPYABLE
(cpp20_counting_semaphore)¶
-
~cpp20_counting_semaphore
()¶
-
bool
try_acquire
()¶
-
void
acquire
()¶
-
bool
try_acquire_until
(hpx::chrono::steady_time_point const &abs_time)¶
-
bool
try_acquire_for
(hpx::chrono::steady_duration const &rel_time)¶
Public Static Functions
-
static constexpr std::ptrdiff_t() hpx::lcos::local::cpp20_counting_semaphore::max()
Protected Types
-
template<>
usingmutex_type
= Mutex¶
-
-
typedef counting_semaphore_var
-
namespace
-
namespace
-
namespace
hpx
-
namespace
lcos
-
namespace
local
-
class
event
¶ - #include <event.hpp>
Event semaphores can be used for synchronizing multiple threads that need to wait for an event to occur. When the event occurs, all threads waiting for the event are woken up.
Public Functions
-
event
()¶ Construct a new event semaphore.
-
bool
occurred
()¶ Check if the event has occurred.
-
void
wait
()¶ Wait for the event to occur.
-
void
set
()¶ Release all threads waiting on this semaphore.
-
void
reset
()¶ Reset the event.
Private Functions
-
void
wait_locked
(std::unique_lock<mutex_type> &l)¶
-
void
set_locked
(std::unique_lock<mutex_type> l)¶
-
-
class
-
namespace
-
namespace
-
namespace
hpx
-
class
latch
¶ - #include <latch.hpp>
Latches are a thread coordination mechanism that allow one or more threads to block until an operation is completed. An individual latch is a singleuse object; once the operation has been completed, the latch cannot be reused.
Subclassed by hpx::lcos::local::latch
Public Functions
-
latch
(std::ptrdiff_t count)¶ Initialize the latch
Requires: count >= 0. Synchronization: None Postconditions: counter_ == count.
-
~latch
()¶ Requires: No threads are blocked at the synchronization point.
- Note
May be called even if some threads have not yet returned from wait() or count_down_and_wait(), provided that counter_ is 0.
- Note
The destructor might not return until all threads have exited wait() or count_down_and_wait().
- Note
It is the caller’s responsibility to ensure that no other thread enters wait() after one thread has called the destructor. This may require additional coordination.
-
void
count_down
(std::ptrdiff_t update)¶ Decrements counter_ by n. Does not block.
Requires: counter_ >= n and n >= 0.
Synchronization: Synchronizes with all calls that block on this latch and with all try_wait calls on this latch that return true .
- Exceptions
Nothing.
:
-
bool
try_wait
() const¶ Returns: With very low probability false. Otherwise counter == 0.
-
void
wait
() const¶ If counter_ is 0, returns immediately. Otherwise, blocks the calling thread at the synchronization point until counter_ reaches 0.
- Exceptions
Nothing.
:
Public Static Functions
-
static constexpr std::ptrdiff_t() hpx::latch::max()
Returns: The maximum value of counter that the implementation supports.
-
-
namespace
lcos
-
namespace
local
-
class
latch
: public hpx::latch¶ - #include <latch.hpp>
A latch maintains an internal counter_ that is initialized when the latch is created. Threads may block at a synchronization point waiting for counter_ to be decremented to 0. When counter_ reaches 0, all such blocked threads are released.
Calls to countdown_and_wait() , count_down() , wait() , is_ready(), count_up() , and reset() behave as atomic operations.
- Note
A hpx::latch is not an LCO in the sense that it has no global id and it can’t be triggered using the action (parcel) mechanism. Use hpx::distributed::latch instead if this is required. It is just a low level synchronization primitive allowing to synchronize a given number of threads.
Public Functions
-
latch
(std::ptrdiff_t count)¶ Initialize the latch
Requires: count >= 0. Synchronization: None Postconditions: counter_ == count.
-
~latch
()¶ Requires: No threads are blocked at the synchronization point.
- Note
May be called even if some threads have not yet returned from wait() or count_down_and_wait(), provided that counter_ is 0.
- Note
The destructor might not return until all threads have exited wait() or count_down_and_wait().
- Note
It is the caller’s responsibility to ensure that no other thread enters wait() after one thread has called the destructor. This may require additional coordination.
-
void
count_down_and_wait
()¶ Decrements counter_ by 1 . Blocks at the synchronization point until counter_ reaches 0.
Requires: counter_ > 0.
Synchronization: Synchronizes with all calls that block on this latch and with all is_ready calls on this latch that return true.
- Exceptions
Nothing.
:
-
bool
is_ready
() const¶ Returns: counter_ == 0. Does not block.
- Exceptions
Nothing.
:
-
void
abort_all
()¶
-
void
count_up
(std::ptrdiff_t n)¶ Increments counter_ by n. Does not block.
Requires: n >= 0.
- Exceptions
Nothing.
:
-
void
reset
(std::ptrdiff_t n)¶ Reset counter_ to n. Does not block.
Requires: n >= 0.
- Exceptions
Nothing.
:
-
bool
reset_if_needed_and_count_up
(std::ptrdiff_t n, std::ptrdiff_t count)¶ Effects: Equivalent to: if (is_ready()) reset(count); count_up(n); Returns: true if the latch was reset
-
class
-
namespace
-
class
-
namespace
hpx
-
namespace
lcos
-
namespace
local
-
-
template<typename
Mutex
>
classupgrade_lock
¶ Public Types
-
template<>
usingmutex_type
= Mutex¶
Public Functions
-
upgrade_lock
(upgrade_lock const&)¶
-
upgrade_lock &
operator=
(upgrade_lock const&)¶
-
upgrade_lock
()¶
-
upgrade_lock
(Mutex &m_)¶
-
upgrade_lock
(upgrade_lock<Mutex> &&other)¶
-
upgrade_lock &
operator=
(upgrade_lock<Mutex> &&other)¶
-
void
swap
(upgrade_lock &other)¶
-
Mutex *
mutex
() const¶
-
Mutex *
release
()¶
-
~upgrade_lock
()¶
-
void
lock
()¶
-
bool
try_lock
()¶
-
void
unlock
()¶
-
operator bool
() const¶
-
bool
owns_lock
() const¶
Friends
-
friend
hpx::lcos::local::upgrade_to_unique_lock
-
template<>
-
template<typename
Mutex
>
classupgrade_to_unique_lock
¶ Public Types
-
template<>
usingmutex_type
= Mutex¶
Public Functions
-
upgrade_to_unique_lock
(upgrade_to_unique_lock const&)¶
-
upgrade_to_unique_lock &
operator=
(upgrade_to_unique_lock const&)¶
-
upgrade_to_unique_lock
(upgrade_lock<Mutex> &m_)¶
-
~upgrade_to_unique_lock
()¶
-
upgrade_to_unique_lock
(upgrade_to_unique_lock<Mutex> &&other)¶
-
upgrade_to_unique_lock &
operator=
(upgrade_to_unique_lock<Mutex> &&other)¶
-
void
swap
(upgrade_to_unique_lock &other)¶
-
operator bool
() const¶
-
bool
owns_lock
() const¶
-
Mutex *
mutex
() const¶
-
template<>
-
template<typename
-
namespace
-
namespace
-
namespace
hpx
-
namespace
lcos
-
namespace
local
-
class
mutex
¶ Subclassed by hpx::lcos::local::timed_mutex
Public Functions
-
mutex
(char const *const description = "")¶
-
~mutex
()¶
-
void
lock
(char const *description, error_code &ec = throws)¶
-
void
lock
(error_code &ec = throws)¶
-
bool
try_lock
(char const *description, error_code &ec = throws)¶
-
bool
try_lock
(error_code &ec = throws)¶
-
void
unlock
(error_code &ec = throws)¶
-
-
class
timed_mutex
: private hpx::lcos::local::mutex¶ Public Functions
-
HPX_NON_COPYABLE
(timed_mutex)¶
-
timed_mutex
(char const *const description = "")¶
-
~timed_mutex
()¶
-
bool
try_lock_until
(hpx::chrono::steady_time_point const &abs_time, char const *description, error_code &ec = throws)¶
-
bool
try_lock_until
(hpx::chrono::steady_time_point const &abs_time, error_code &ec = throws)¶
-
bool
try_lock_for
(hpx::chrono::steady_duration const &rel_time, char const *description, error_code &ec = throws)¶
-
bool
try_lock_for
(hpx::chrono::steady_duration const &rel_time, error_code &ec = throws)¶
-
void
lock
(char const *description, error_code &ec = throws)
-
void
lock
(error_code &ec = throws)
-
bool
try_lock
(char const *description, error_code &ec = throws)
-
bool
try_lock
(error_code &ec = throws)
-
void
unlock
(error_code &ec = throws)
-
-
class
-
namespace
-
namespace
threads
Typedefs
-
using
thread_id_ref_type
= thread_id_ref¶
-
using
thread_self
= coroutines::detail::coroutine_self¶
Functions
-
thread_id
get_self_id
()¶ The function get_self_id returns the HPX thread id of the current thread (or zero if the current thread is not a HPX thread).
-
thread_self *
get_self_ptr
()¶ The function get_self_ptr returns a pointer to the (OS thread specific) self reference to the current HPX thread.
-
using
-
namespace
-
namespace
hpx
-
namespace
lcos
-
namespace
local
-
struct
no_mutex
¶
-
struct
-
namespace
-
namespace
Defines
-
HPX_ONCE_INIT
¶
-
namespace
hpx
-
namespace
hpx
-
namespace
lcos
-
namespace
local
Typedefs
-
using
recursive_mutex
= detail::recursive_mutex_impl<>¶
-
using
-
namespace
-
namespace
-
namespace
hpx
-
namespace
lcos
-
namespace
local
Typedefs
-
namespace
-
namespace
-
namespace
hpx
-
namespace
lcos
-
namespace
local
Typedefs
-
typedef sliding_semaphore_var
sliding_semaphore
¶
-
template<typename
Mutex
= hpx::lcos::local::spinlock>
classsliding_semaphore_var
¶ - #include <sliding_semaphore.hpp>
A semaphore is a protected variable (an entity storing a value) or abstract data type (an entity grouping several variables that may or may not be numerical) which constitutes the classic method for restricting access to shared resources, such as shared memory, in a multiprogramming environment. Semaphores exist in many variants, though usually the term refers to a counting semaphore, since a binary semaphore is better known as a mutex. A counting semaphore is a counter for a set of available resources, rather than a locked/unlocked flag of a single resource. It was invented by Edsger Dijkstra. Semaphores are the classic solution to preventing race conditions in the dining philosophers problem, although they do not prevent resource deadlocks.
Sliding semaphores can be used for synchronizing multiple threads as well: one thread waiting for several other threads to touch (signal) the semaphore, or several threads waiting for one other thread to touch this semaphore. The difference to a counting semaphore is that a sliding semaphore will not limit the number of threads which are allowed to proceed, but will make sure that the difference between the (arbitrary) number passed to set and wait does not exceed a given threshold.
Public Functions
-
sliding_semaphore_var
(std::int64_t max_difference, std::int64_t lower_limit = 0)¶ Construct a new sliding semaphore.
-
void
set_max_difference
(std::int64_t max_difference, std::int64_t lower_limit = 0)¶ Set/Change the difference that will cause the semaphore to trigger.
-
void
wait
(std::int64_t upper_limit)¶ Wait for the semaphore to be signaled.
- Parameters
upper_limit
: [in] The new upper limit. The calling thread will be suspended if the difference between this value and the largest lower_limit which was set by signal() is larger than the max_difference.
-
bool
try_wait
(std::int64_t upper_limit = 1)¶ Try to wait for the semaphore to be signaled.
- Return
The function returns true if the calling thread would not block if it was calling wait().
- Parameters
upper_limit
: [in] The new upper limit. The calling thread will be suspended if the difference between this value and the largest lower_limit which was set by signal() is larger than the max_difference.
-
void
signal
(std::int64_t lower_limit)¶ Signal the semaphore.
- Parameters
lower_limit
: [in] The new lower limit. This will update the current lower limit of this semaphore. It will also re-schedule all suspended threads for which their associated upper limit is not larger than the lower limit plus the max_difference.
Private Types
-
typedef Mutex
mutex_type
¶
-
-
typedef sliding_semaphore_var
-
namespace
-
namespace
-
namespace
hpx
-
namespace
hpx
-
namespace
hpx
-
namespace
lcos
-
namespace
-
namespace
hpx
Functions
-
template<typename
Callback
>stop_callback
(stop_token, Callback)¶
-
void
swap
(stop_token &lhs, stop_token &rhs)¶
-
void
swap
(stop_source &lhs, stop_source &rhs)¶
Variables
-
constexpr nostopstate_t
nostopstate
= {}¶
-
template<typename
Callback
>
classstop_callback
Public Types
-
template<>
usingcallback_type
= Callback¶
Public Functions
-
template<typename
CB
, typenameEnable
= std::enable_if_t<std::is_constructible_v<Callback, CB>>>stop_callback
(stop_token const &st, CB &&cb)¶
-
template<typename
CB
, typenameEnable
= std::enable_if_t<std::is_constructible_v<Callback, CB>>>stop_callback
(stop_token &&st, CB &&cb)¶
-
~stop_callback
()¶
-
stop_callback
(stop_callback const&)¶
-
stop_callback
(stop_callback&&)¶
-
stop_callback &
operator=
(stop_callback const&)¶
-
stop_callback &
operator=
(stop_callback&&)¶
Private Functions
-
void
execute
()¶
-
template<>
-
class
stop_source
¶ Public Functions
-
stop_source
()¶
-
stop_source
(nostopstate_t)¶
-
stop_source
(stop_source const &rhs)¶
-
stop_source
(stop_source&&)¶
-
stop_source &
operator=
(stop_source const &rhs)¶
-
stop_source &
operator=
(stop_source&&)¶
-
~stop_source
()¶
-
void
swap
(stop_source &s)¶
-
stop_token
get_token
() const¶
-
bool
stop_possible
() const¶
-
bool
stop_requested
() const¶
-
bool
request_stop
()¶
-
-
class
stop_token
¶ -
Public Functions
-
stop_token
()¶
-
stop_token
(stop_token const &rhs)¶
-
stop_token
(stop_token&&)¶
-
stop_token &
operator=
(stop_token const &rhs)¶
-
stop_token &
operator=
(stop_token&&)¶
-
~stop_token
()¶
-
void
swap
(stop_token &s)¶
-
bool
stop_requested
() const¶
-
bool
stop_possible
() const¶
-
-
namespace
p2300_stop_token
¶ Functions
-
template<typename
Callback
>in_place_stop_callback
(in_place_stop_token, Callback)¶
-
template<typename
Callback
>
classin_place_stop_callback
Public Types
-
template<>
usingcallback_type
= Callback¶
Public Functions
-
template<typename
CB
, typenameEnable
= std::enable_if_t<std::is_constructible_v<Callback, CB>>>in_place_stop_callback
(in_place_stop_token const &st, CB &&cb)¶
-
template<typename
CB
, typenameEnable
= std::enable_if_t<std::is_constructible_v<Callback, CB>>>in_place_stop_callback
(in_place_stop_token &&st, CB &&cb)¶
-
~in_place_stop_callback
()¶
-
in_place_stop_callback
(in_place_stop_callback const&)¶
-
in_place_stop_callback
(in_place_stop_callback&&)¶
-
in_place_stop_callback &
operator=
(in_place_stop_callback const&)¶
-
in_place_stop_callback &
operator=
(in_place_stop_callback&&)¶
Private Functions
-
void
execute
()¶
Private Members
-
HPX_NO_UNIQUE_ADDRESS Callback hpx::p2300_stop_token::in_place_stop_callback::callback_
-
in_place_stop_source *
source_
¶
-
template<>
-
class
in_place_stop_source
¶ Public Functions
-
in_place_stop_source
()¶
-
~in_place_stop_source
()¶
-
in_place_stop_source
(in_place_stop_source const&)¶
-
in_place_stop_source
(in_place_stop_source&&)¶
-
in_place_stop_source &
operator=
(in_place_stop_source const&)¶
-
in_place_stop_source &
operator=
(in_place_stop_source&&)¶
-
in_place_stop_token
get_token
() const¶
-
bool
request_stop
()¶
-
bool
stop_requested
() const¶
-
bool
stop_possible
() const¶
Private Functions
Friends
-
friend
hpx::p2300_stop_token::in_place_stop_token
-
friend
hpx::p2300_stop_token::in_place_stop_callback
-
-
class
in_place_stop_token
¶ -
Public Functions
-
constexpr
in_place_stop_token
()¶
-
in_place_stop_token
(in_place_stop_token const &rhs)¶
-
in_place_stop_token
(in_place_stop_token &&rhs)¶
-
in_place_stop_token &
operator=
(in_place_stop_token const &rhs)¶
-
in_place_stop_token &
operator=
(in_place_stop_token &&rhs)¶
-
bool
stop_requested
() const¶
-
bool
stop_possible
() const¶
-
void
swap
(in_place_stop_token &rhs)¶
Private Functions
-
in_place_stop_token
(in_place_stop_source const *source)¶
Private Members
-
in_place_stop_source const *
source_
¶
-
constexpr
-
struct
never_stop_token
¶ Public Types
-
template<typename>
usingcallback_type
= callback_impl¶
Public Static Functions
-
static constexpr bool
stop_requested
()¶
-
static constexpr bool
stop_possible
()¶
Friends
-
friend constexpr bool
operator==
(never_stop_token const&, never_stop_token const&)¶
-
struct
callback_impl
¶ Public Functions
-
template<typename
Callback
>
constexprcallback_impl
(never_stop_token, Callback&&)¶
-
template<typename
-
template<typename>
-
template<typename
-
template<typename