TaskGroup class
Waits for a group of tasks (fork/join).
- Use
import ThinkMeta.ConcurrentTasks.Synchronization.TaskGroup;- Namespace
ThinkMeta::ConcurrentTasks::Synchronization- Inherits
Waitable,INotifyTaskStateChange
Syntax
using TaskGroup = _TaskGroup<SuspensionKind::Multiple>;
using TaskGroup_s = _TaskGroup<SuspensionKind::Single>;Template parameters
_SuspensionKindSuspensionKindSuspensionKind::Multiple: any number of waiting tasks;SuspensionKind::Single: at most one waiting task at a time, cheaper, with timeouts.
Remarks
AddTask counts a task in, its exit counts it out, and Wait passes once the count is 0. Comes as TaskGroup (any number of waiters) and TaskGroup_s (one waiter; also Wait with a timeout). Wait suspends and needs a task or an OS thread converted with ConvertThreadToTask. The group is reusable: after the count reached 0, new tasks may be added for the next round. The group may be a local object of the function that waits for it: once Wait has returned (or TryWait returned true) and no other task waits on it, it may be destroyed; the destructor waits for an exit notification that is still finishing. Destroy it only after all its tasks have exited.
See also
Names
| Name | Description |
|---|---|
TaskGroup |
Task group for any number of waiting tasks (no timeouts). |
TaskGroup_s |
Task group for at most one waiting task.
Cheaper than |
Constructors
TaskGroup
~TaskGroup
Destroys the group.
Syntax
~TaskGroup() noexcept;Remarks
Waits (briefly) until the exit notification of the last task has finished.
Methods
AddTask
Adds a task to the group.
Syntax
void AddTask(ITask* task) noexcept;Parameters
taskITask*- The task to count in; the group becomes its exit callback (
ITask::SetNotifyCallback, which replaces any callback set before: a task belongs to one group at a time).
Remarks
Call it before the task is added to a scheduler. A task of the group may add further tasks while it runs, since the group cannot complete before it exits. From outside the group, add tasks only while the group cannot complete, or before anyone waits for the round they belong to. Never suspends; any thread. Only an exit counts a task out: if it is then not started (a start by time that returns false, see Tasks::Task::Schedule), start it otherwise or report its exit yourself (Tasks::Task::OnTaskExited forwards to the group), or Wait never returns.
See also
OnTaskExited
Counts an exited task out of the group.
Syntax
void OnTaskExited() noexcept override;Remarks
Called when a task of the group exits (on its scheduler thread); the last one resumes the waiter(s). Application code does not call it.
TryWait
Tells whether all tasks of the group have exited.
Syntax
[[nodiscard]] bool TryWait() noexcept;Return value
Type: bool
true if no task of the group is left (count 0); otherwise false.
Remarks
Never suspends; any thread.
See also
Generated from ThinkMeta.ConcurrentTasks.API @ 137ec1d (2026-10-17).