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

Minimal structured-concurrency helper over ThreadPool futures. More...

#include <thread_pool.H>

Collaboration diagram for Aleph::TaskGroup:
[legend]

Public Member Functions

 TaskGroup (ThreadPool &pool=default_pool()) noexcept
 
 TaskGroup (const TaskGroup &)=delete
 Deleted copy constructor.
 
TaskGroupoperator= (const TaskGroup &)=delete
 Deleted copy assignment operator.
 
 TaskGroup (TaskGroup &&)=delete
 Deleted move constructor.
 
TaskGroupoperator= (TaskGroup &&)=delete
 Deleted move assignment operator.
 
 ~TaskGroup ()
 
template<typename F , typename... Args>
void launch (F &&f, Args &&... args)
 Launch a task that belongs to this group.
 
template<typename F , typename... Args>
void run (F &&f, Args &&... args)
 Compatibility wrapper for launch().
 
void wait ()
 Wait for all launched tasks and rethrow the first exception.
 
size_t size () const noexcept
 Return the number of tasks currently tracked by the group.
 
bool is_empty () const noexcept
 Return true if the group has no pending tasks.
 

Private Member Functions

void drain (const bool propagate)
 

Static Private Member Functions

template<typename F , typename... Args>
static auto make_invocable (F &&f, Args &&... args)
 

Private Attributes

ThreadPoolpool_ = nullptr
 
std::vector< std::future< void > > tasks_
 

Detailed Description

Minimal structured-concurrency helper over ThreadPool futures.

A TaskGroup lets callers launch a set of related tasks and then wait for all of them as a unit. Exceptions are propagated cleanly from wait(), and the destructor joins outstanding tasks without throwing.

Definition at line 2331 of file thread_pool.H.

Constructor & Destructor Documentation

◆ TaskGroup() [1/3]

Aleph::TaskGroup::TaskGroup ( ThreadPool pool = default_pool())
inlineexplicitnoexcept

Definition at line 2370 of file thread_pool.H.

References Aleph::default_pool().

◆ TaskGroup() [2/3]

Aleph::TaskGroup::TaskGroup ( const TaskGroup )
delete

Deleted copy constructor.

◆ TaskGroup() [3/3]

Aleph::TaskGroup::TaskGroup ( TaskGroup &&  )
delete

Deleted move constructor.

◆ ~TaskGroup()

Aleph::TaskGroup::~TaskGroup ( )
inline

Definition at line 2385 of file thread_pool.H.

Member Function Documentation

◆ drain()

void Aleph::TaskGroup::drain ( const bool  propagate)
inlineprivate

Definition at line 2349 of file thread_pool.H.

◆ is_empty()

bool Aleph::TaskGroup::is_empty ( ) const
inlinenoexcept

Return true if the group has no pending tasks.

Definition at line 2415 of file thread_pool.H.

◆ launch()

template<typename F , typename... Args>
void Aleph::TaskGroup::launch ( F &&  f,
Args &&...  args 
)
inline

Launch a task that belongs to this group.

Definition at line 2389 of file thread_pool.H.

References Aleph::ThreadPool::enqueue().

◆ make_invocable()

template<typename F , typename... Args>
static auto Aleph::TaskGroup::make_invocable ( F &&  f,
Args &&...  args 
)
inlinestaticprivate

Definition at line 2337 of file thread_pool.H.

◆ operator=() [1/2]

TaskGroup & Aleph::TaskGroup::operator= ( const TaskGroup )
delete

Deleted copy assignment operator.

◆ operator=() [2/2]

TaskGroup & Aleph::TaskGroup::operator= ( TaskGroup &&  )
delete

Deleted move assignment operator.

◆ run()

template<typename F , typename... Args>
void Aleph::TaskGroup::run ( F &&  f,
Args &&...  args 
)
inline

Compatibility wrapper for launch().

Definition at line 2403 of file thread_pool.H.

◆ size()

size_t Aleph::TaskGroup::size ( ) const
inlinenoexcept

Return the number of tasks currently tracked by the group.

Definition at line 2412 of file thread_pool.H.

◆ wait()

void Aleph::TaskGroup::wait ( )
inline

Wait for all launched tasks and rethrow the first exception.

Definition at line 2409 of file thread_pool.H.

Member Data Documentation

◆ pool_

ThreadPool* Aleph::TaskGroup::pool_ = nullptr
private

Definition at line 2333 of file thread_pool.H.

◆ tasks_

std::vector<std::future<void> > Aleph::TaskGroup::tasks_
private

Definition at line 2334 of file thread_pool.H.


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