63 friend class Executor;
141 template <
typename F>
165 template <
typename P,
typename F>
166 auto async(P&& params, F&& f);
194 template <
typename F>
215 template <
typename P,
typename F>
257 template <
typename F,
typename... Tasks>
258requires (std::same_as<std::decay_t<Tasks>,
AsyncTask> && ...)
301 requires (std::same_as<std::decay_t<Tasks>,
AsyncTask> && ...)
342 template <
typename F,
typename I>
343requires (!std::same_as<std::decay_t<I>,
AsyncTask>)
388 template <TaskParameters P,
typename F,
typename I>
389 requires (!std::same_as<std::decay_t<I>,
AsyncTask>)
425 template <
typename F,
typename... Tasks>
426requires (std::same_as<std::decay_t<Tasks>,
AsyncTask> && ...)
462 requires (std::same_as<std::decay_t<Tasks>,
AsyncTask> && ...)
498 template <
typename F,
typename I>
499 requires (!std::same_as<std::decay_t<I>,
AsyncTask>)
537 template <TaskParameters P,
typename F,
typename I>
538 requires (!std::same_as<std::decay_t<I>,
AsyncTask>)
714 _executor {executor},
716 _node_base {NSTATE::IMPLICITLY_ANCHORED, ESTATE::NONE, nullptr, 0} {
727 ExplicitAnchorGuard anchor(&_node_base);
728 _executor._corun_until(_worker, [
this] () ->
bool {
729 return _node_base._join_counter.load(std::memory_order_acquire) == 0;
732 _node_base._rethrow_exception();
737 _node_base._estate.fetch_or(ESTATE::CANCELLED, std::memory_order_relaxed);
742 return _node_base._estate.load(std::memory_order_relaxed) & ESTATE::CANCELLED;
747 return _node_base._join_counter.load(std::memory_order_relaxed);
761template <
typename P,
typename F>
763 _node_base._join_counter.fetch_add(1, std::memory_order_relaxed);
764 _executor._silent_async(
765 std::forward<P>(params), std::forward<F>(f),
nullptr, &_node_base
780template <
typename P,
typename F>
782 _node_base._join_counter.fetch_add(1, std::memory_order_relaxed);
783 return _executor._async(
784 std::forward<P>(params), std::forward<F>(f),
nullptr, &_node_base
793template <
typename F,
typename... Tasks>
794requires (std::same_as<std::decay_t<Tasks>,
AsyncTask> && ...)
803requires (std::same_as<std::decay_t<Tasks>,
AsyncTask> && ...)
805 P&& params, F&& func, Tasks&&... tasks
807 std::array<
AsyncTask,
sizeof...(Tasks)> array = { std::forward<Tasks>(tasks)... };
809 std::forward<P>(params), std::forward<F>(func), array.begin(), array.end()
814template <
typename F,
typename I>
815requires (!std::same_as<std::decay_t<I>,
AsyncTask>)
821template <TaskParameters P,
typename F,
typename I>
822requires (!std::same_as<std::decay_t<I>,
AsyncTask>)
824 P&& params, F&& func, I first, I last
826 _node_base._join_counter.fetch_add(1, std::memory_order_relaxed);
827 return _executor._silent_dependent_async(
828 std::forward<P>(params), std::forward<F>(func), first, last,
nullptr, &_node_base
837template <
typename F,
typename... Tasks>
838requires (std::same_as<std::decay_t<Tasks>,
AsyncTask> && ...)
845requires (std::same_as<std::decay_t<Tasks>,
AsyncTask> && ...)
847 std::array<
AsyncTask,
sizeof...(Tasks)> array = { std::forward<Tasks>(tasks)... };
849 std::forward<P>(params), std::forward<F>(func), array.begin(), array.end()
854template <
typename F,
typename I>
855requires (!std::same_as<std::decay_t<I>,
AsyncTask>)
861template <TaskParameters P,
typename F,
typename I>
862requires (!std::same_as<std::decay_t<I>,
AsyncTask>)
864 _node_base._join_counter.fetch_add(1, std::memory_order_relaxed);
865 return _executor._dependent_async(
866 std::forward<P>(params), std::forward<F>(func), first, last,
nullptr, &_node_base
878 TF_THROW(
"task_group can only created by a worker of the executor");
880 return TaskGroup(*
this, *w);
class to hold a dependent asynchronous task with shared ownership
Definition async_task.hpp:45
class to create an empty task parameter for compile-time optimization
Definition graph.hpp:166
class to create an executor
Definition executor.hpp:62
TaskGroup task_group()
creates a task group that executes a collection of asynchronous tasks
Definition task_group.hpp:875
Worker * this_worker()
queries pointer to the calling worker if it belongs to this executor, otherwise returns nullptr
void corun()
corun all tasks spawned by this task group with other workers
Definition task_group.hpp:725
void cancel()
cancel all tasks in this task group
Definition task_group.hpp:736
size_t size() const
queries the number of tasks currently in this task group
Definition task_group.hpp:746
tf::AsyncTask silent_dependent_async(F &&func, Tasks &&... tasks)
runs the given function asynchronously when the given predecessors finish
Definition task_group.hpp:795
auto async(F &&f)
runs the given callable asynchronously
Definition task_group.hpp:775
TaskGroup & operator=(TaskGroup &&)=delete
disabled copy assignment
bool is_cancelled()
queries if the task group has been cancelled
Definition task_group.hpp:741
TaskGroup(TaskGroup &&)=delete
disabled move constructor
auto dependent_async(F &&func, Tasks &&... tasks)
runs the given function asynchronously when the given predecessors finish
Definition task_group.hpp:839
TaskGroup(const TaskGroup &)=delete
disabled copy constructor
Executor & executor()
obtains the executor that creates this task group
Definition task_group.hpp:720
void silent_async(F &&f)
runs the given function asynchronously without returning any future object
Definition task_group.hpp:756
class to create a worker in an executor
Definition worker.hpp:55
determines if a type is a task parameter type
Definition graph.hpp:177
taskflow namespace
Definition small_vector.hpp:20