|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
RAII guard that leaves no thread joinable when it goes out of scope, cancelling gate first so any thread still blocked in Deterministic_Start_Gate::arrive_and_wait() wakes up instead of waiting forever.
More...
#include <concurrency_test_utils.H>
Public Member Functions | |
| Joining_Thread_Guard (std::vector< std::thread > &threads, Deterministic_Start_Gate &gate) noexcept | |
| Joining_Thread_Guard (const Joining_Thread_Guard &)=delete | |
| Joining_Thread_Guard & | operator= (const Joining_Thread_Guard &)=delete |
| void | dismiss () noexcept |
| Mark the launch loop as having completed without throwing. | |
| ~Joining_Thread_Guard () | |
Private Attributes | |
| std::vector< std::thread > & | threads_ |
| Deterministic_Start_Gate & | gate_ |
| bool | launch_completed_ = false |
RAII guard that leaves no thread joinable when it goes out of scope, cancelling gate first so any thread still blocked in Deterministic_Start_Gate::arrive_and_wait() wakes up instead of waiting forever.
Launching a cohort of worker threads with std::vector::emplace_back can throw partway through (typically std::system_error from the OS refusing to create another thread). Without this guard, threads already started would stay blocked on the shared gate – it will never reach its full expected arrival count – and destroying a still-joinable std::thread (as the enclosing std::vector<std::thread> does when unwound by the exception) calls std::terminate(). Keeping this guard alive for the entire launch-and-join scope fixes both problems on any exit path, normal or exceptional.
Definition at line 182 of file concurrency_test_utils.H.
|
inlinenoexcept |
Definition at line 189 of file concurrency_test_utils.H.
|
delete |
|
inline |
Definition at line 202 of file concurrency_test_utils.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::Testing::Deterministic_Start_Gate::cancel(), gate_, launch_completed_, and threads_.
|
inlinenoexcept |
Mark the launch loop as having completed without throwing.
Call once, right after the last threads.emplace_back(...).
Definition at line 200 of file concurrency_test_utils.H.
References launch_completed_.
|
delete |
|
private |
Definition at line 185 of file concurrency_test_utils.H.
Referenced by ~Joining_Thread_Guard().
Definition at line 186 of file concurrency_test_utils.H.
Referenced by ~Joining_Thread_Guard(), and dismiss().
|
private |
Definition at line 184 of file concurrency_test_utils.H.
Referenced by ~Joining_Thread_Guard().