tmc::fork_clang()#
tmc::fork_clang() is a HALO-optimized version of spawn().fork() that uses the [[clang::coro_await_elidable_argument]] attribute when compiled with Clang 20+.
For HALO to work, fork_clang() must be awaited directly as a prvalue in a co_await expression. Storing the result in a variable before awaiting prevents HALO from being applied.
// HALO: fork_clang() is directly awaited
auto forked = co_await tmc::fork_clang(some_task());
do_some_work();
co_await std::move(forked);
// Non-HALO: fork_clang() stored in variable
auto dummy = tmc::fork_clang(some_task());
auto forked = co_await std::move(dummy);
do_some_work();
co_await std::move(forked);
// Non-HALO equivalent: spawn().fork() - due to member function call,
// this cannot be elided
auto forked = tmc::spawn(some_task()).fork();
auto results = co_await std::move(forked);
Main Documentation#
For the non-HALO version, see tmc::spawn().
API Reference#
-
template<typename Awaitable, typename Exec = tmc::ex_any*>
aw_fork_clang<tmc::detail::forward_awaitable<Awaitable>> tmc::fork_clang(Awaitable &&Aw, Exec &&Executor = tmc::current_executor(), size_t Priority = tmc::current_priority())# Similar to
tmc::spawn(Aw).fork()but allows the child task’s allocation to be elided by combining it into the parent’s allocation (HALO). This works by using specific attributes that are only available on Clang 20+. You can safely call this function on other compilers but no HALO-specific optimizations will be applied.IMPORTANT: This returns a dummy awaitable. For HALO to work, you should not store the dummy awaitable. Instead,
co_awaitthis expression immediately, which returns the real awaitable that you can use to join the forked task later. Proper usage:auto forked_task = co_await tmc::fork_clang(some_task()); do_some_other_work(); co_await std::move(forked_task);