|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Read-only cooperative cancellation token. More...
#include <thread_pool.H>
Classes | |
| class | ConditionVariableRegistration |
| RAII guard for condition variable cancellation registration. More... | |
Public Member Functions | |
| CancellationToken ()=default | |
| Default constructor. | |
| bool | stop_requested () const noexcept |
| Return true if cancellation has been requested. | |
| bool | is_cancellation_requested () const noexcept |
| Synonym for stop_requested(). | |
| void | throw_if_cancellation_requested () const |
| Throw operation_canceled if cancellation was requested. | |
| bool | valid () const noexcept |
| Return true if the token is connected to a source. | |
| ConditionVariableRegistration | notify_on_cancel (std::condition_variable &cv) const |
| Request notification of a condition variable on cancellation. | |
| ConditionVariableRegistration | notify_on_cancel (std::condition_variable &cv, std::mutex &mutex) const |
| Request notification of a condition variable on cancellation, without missing it. | |
Private Member Functions | |
| CancellationToken (std::shared_ptr< cancellation_detail::Exact_State > state) noexcept | |
Private Attributes | |
| std::shared_ptr< cancellation_detail::Exact_State > | state_ |
Friends | |
| class | CancellationSource |
Read-only cooperative cancellation token.
Tokens are cheap to copy and can be captured by tasks. They never force a task to stop; instead, user code or higher-level helpers can observe the request and exit gracefully.
Definition at line 292 of file thread_pool.H.
|
inlineexplicitprivatenoexcept |
Definition at line 296 of file thread_pool.H.
|
default |
Default constructor.
|
inlinenoexcept |
Synonym for stop_requested().
Definition at line 395 of file thread_pool.H.
References stop_requested().
|
inline |
Request notification of a condition variable on cancellation.
This is primarily intended for blocking helpers that need to wake up promptly when cooperative cancellation is requested.
Definition at line 426 of file thread_pool.H.
References state_, and stop_requested().
Referenced by Aleph::BoundedChannel< T >::wait_with_cancellation().
|
inline |
Request notification of a condition variable on cancellation, without missing it.
mutex is the mutex that the waiters on cv hold while they check their condition and wait. A cancellation takes and releases mutex before it notifies cv, so it cannot come between the check of the token and the wait: a waiter that checks stop_requested() under mutex after this call, and waits on cv for that check, always wakes up. For example:
A cancellation takes mutex to notify the registration, and ending the registration, by destroying or assigning its guard, waits for a notification of it in progress. So, to avoid a deadlock, treat both requesting the cancellation and ending the registration as taking mutex:
mutex. Declaring the guard before the lock, as above, ends the registration after the lock has released the mutex.mutex, including in these two ways. For example, two threads that each hold the mutex of one registration and end the other one can deadlock.Ending a registration waits for any notification of it in progress; after that, the cancellation no longer uses cv and mutex through it.
| cv | Condition variable to notify on cancellation. |
| mutex | Mutex that the waiters on cv hold. |
| std::bad_alloc | if the registration cannot be allocated. |
Definition at line 479 of file thread_pool.H.
References state_, and stop_requested().
|
inlinenoexcept |
Return true if cancellation has been requested.
Definition at line 389 of file thread_pool.H.
References Aleph::and, and state_.
Referenced by is_cancellation_requested(), notify_on_cancel(), notify_on_cancel(), throw_if_cancellation_requested(), and Aleph::BoundedChannel< T >::wait_with_cancellation().
|
inline |
Throw operation_canceled if cancellation was requested.
Definition at line 401 of file thread_pool.H.
References stop_requested().
Referenced by Aleph::parallel_detail::throw_if_canceled(), Aleph::parallel_detail::throw_if_parallel_canceled(), and Aleph::BoundedChannel< T >::wait_with_cancellation().
|
inlinenoexcept |
Return true if the token is connected to a source.
Definition at line 408 of file thread_pool.H.
References state_.
|
friend |
Definition at line 299 of file thread_pool.H.
|
private |
Definition at line 294 of file thread_pool.H.
Referenced by notify_on_cancel(), notify_on_cancel(), stop_requested(), and valid().