ThreadSchedule 2.2.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::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>
void 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::task_group< Pool >

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

Usage
ThreadPool pool(4);
{
task_group group(pool);
group.submit([]{ do_work_a(); });
group.submit([]{ do_work_b(); });
group.wait(); // blocks until both complete
}
ThreadPoolBase< IndefiniteWait > ThreadPool
General-purpose thread pool with indefinite blocking wait.
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.
Template Parameters
PoolThread pool type (must support submit(Callable)).

Definition at line 48 of file task_group.hpp.

Constructor & Destructor Documentation

◆ task_group() [1/2]

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

Definition at line 51 of file task_group.hpp.

Referenced by operator=(), and task_group().

◆ task_group() [2/2]

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

References task_group().

◆ ~task_group()

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

Definition at line 56 of file task_group.hpp.

References wait().

Member Function Documentation

◆ operator=()

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

References task_group().

◆ pending()

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

Number of pending (not yet waited) tasks.

Definition at line 116 of file task_group.hpp.

◆ submit()

template<typename Pool>
template<typename F>
void threadschedule::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 74 of file task_group.hpp.

◆ wait()

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

Block until all submitted tasks complete.

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

Definition at line 87 of file task_group.hpp.

Referenced by ~task_group().


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