ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::advanced::task_group< Pool > Class Template Reference

Scoped task group that ensures all submitted work completes before the group is destroyed. More...

#include <task_group.hpp>

Public Member Functions

 task_group (Pool &pool)
 
 task_group (task_group const &)=delete
 
auto operator= (task_group const &) -> task_group &=delete
 
 ~task_group ()
 
template<typename F >
auto submit (F &&f)
 Submit a void() callable to the group.
 
void wait ()
 Block until all submitted tasks complete.
 
auto pending () const -> size_t
 Number of pending (not yet waited) tasks.
 

Detailed Description

template<typename Pool>
class threadschedule::advanced::task_group< Pool >

Scoped task group that ensures all submitted work completes before the group is destroyed.

Usage
{
task_group group(pool);
group.submit([]{ do_work_a(); });
group.submit([]{ do_work_b(); });
group.wait(); // blocks until both complete
}
Scoped task group that ensures all submitted work completes before the group is destroyed.
Value type for pool worker count.
Exception handling
If any task throws, the first captured exception is rethrown from wait(). All remaining tasks still run to completion.
Destructor
The destructor calls wait() if it has not been called already, ensuring that tasks never outlive the group. Note: if the destructor must wait for slow tasks, it will block. Tasks submitted recursively by a task already running in this group are executed inline. This preserves progress when every pool worker is occupied by a parent task waiting for its grouped children.
Template Parameters
PoolThread pool type (must support submit(Callable)).

Definition at line 82 of file task_group.hpp.

Constructor & Destructor Documentation

◆ task_group() [1/2]

template<typename Pool >
threadschedule::advanced::task_group< Pool >::task_group ( Pool &  pool)
inlineexplicit

Definition at line 89 of file task_group.hpp.

◆ task_group() [2/2]

template<typename Pool >
threadschedule::advanced::task_group< Pool >::task_group ( task_group< Pool > const &  )
delete

◆ ~task_group()

template<typename Pool >
threadschedule::advanced::task_group< Pool >::~task_group ( )
inline

Member Function Documentation

◆ operator=()

template<typename Pool >
auto threadschedule::advanced::task_group< Pool >::operator= ( task_group< Pool > const &  ) -> task_group &=delete
delete

◆ pending()

template<typename Pool >
auto threadschedule::advanced::task_group< Pool >::pending ( ) const -> size_t
inline

Number of pending (not yet waited) tasks.

Definition at line 225 of file task_group.hpp.

◆ submit()

template<typename Pool >
template<typename F >
auto threadschedule::advanced::task_group< Pool >::submit ( F &&  f)
inline

Submit a void() callable to the group.

The returned future is tracked internally; you do not need to store it yourself.

Definition at line 113 of file task_group.hpp.

References threadschedule::detail::task_group_is_current_worker().

◆ wait()

template<typename Pool >
void threadschedule::advanced::task_group< Pool >::wait ( )
inline

Block until all submitted tasks complete.

Tasks submitted to this group by a task currently being waited on are included in the same wait operation.

Exceptions
Rethrowsthe first exception from any task. All tasks are still waited on even if one throws.

Definition at line 187 of file task_group.hpp.

Referenced by threadschedule::advanced::task_group< Pool >::~task_group().


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