Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Testing::detail::Joining_Thread_Guard Class Reference

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>

Collaboration diagram for Aleph::Testing::detail::Joining_Thread_Guard:
[legend]

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Joining_Thread_Guard() [1/2]

Aleph::Testing::detail::Joining_Thread_Guard::Joining_Thread_Guard ( std::vector< std::thread > &  threads,
Deterministic_Start_Gate &  gate 
)
inlinenoexcept

Definition at line 189 of file concurrency_test_utils.H.

◆ Joining_Thread_Guard() [2/2]

Aleph::Testing::detail::Joining_Thread_Guard::Joining_Thread_Guard ( const Joining_Thread_Guard &  )
delete

◆ ~Joining_Thread_Guard()

Aleph::Testing::detail::Joining_Thread_Guard::~Joining_Thread_Guard ( )
inline

Member Function Documentation

◆ dismiss()

void Aleph::Testing::detail::Joining_Thread_Guard::dismiss ( )
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_.

◆ operator=()

Joining_Thread_Guard & Aleph::Testing::detail::Joining_Thread_Guard::operator= ( const Joining_Thread_Guard &  )
delete

Member Data Documentation

◆ gate_

Deterministic_Start_Gate& Aleph::Testing::detail::Joining_Thread_Guard::gate_
private

Definition at line 185 of file concurrency_test_utils.H.

Referenced by ~Joining_Thread_Guard().

◆ launch_completed_

bool Aleph::Testing::detail::Joining_Thread_Guard::launch_completed_ = false
private

Definition at line 186 of file concurrency_test_utils.H.

Referenced by ~Joining_Thread_Guard(), and dismiss().

◆ threads_

std::vector<std::thread>& Aleph::Testing::detail::Joining_Thread_Guard::threads_
private

Definition at line 184 of file concurrency_test_utils.H.

Referenced by ~Joining_Thread_Guard().


The documentation for this class was generated from the following file: