feat(async): add ThreadExecutor, FuturePool, AsyncChannel, bounded parallel_for, and spawn fix (M-ASYNC-04)

This commit is contained in:
faumaray committed 2026-12-01 10:15:03 +03:00
1 parent 5c24f8e84f
commit b2c84114fe
9 files changed
+4763 -8

No files matched your search

+17 -5
View File
@@ -276,29 +276,41 @@ struct ScheduleAwaiter {
// coroutine owns the task; its frame self-destroys on completion. An
// exception escaping the task terminates (there is no awaiter to receive
// it) — handle errors inside the task.
//
// The wrapper starts suspended and is posted only after its ramp function has
// returned. An eagerly started wrapper that posted itself from its first
// co_await could be resumed and destroyed by an executor worker while the
// spawning thread was still inside the ramp (data race reported by TSan when
// spawning from a non-worker thread onto a multi-worker executor; W11).
namespace Detail
{
struct DetachedTask {
struct promise_type {
DetachedTask get_return_object() noexcept { return {}; }
std::suspend_never initial_suspend() noexcept { return {}; }
DetachedTask get_return_object() noexcept
{
return DetachedTask{
std::coroutine_handle<promise_type>::from_promise(*this)};
}
std::suspend_always initial_suspend() noexcept { return {}; }
std::suspend_never final_suspend() noexcept { return {}; }
void return_void() noexcept {}
void unhandled_exception() noexcept { std::terminate(); }
};
std::coroutine_handle<promise_type> handle{};
};
inline DetachedTask spawn_impl(Executor& executor, Coro::Task<void> task)
inline DetachedTask spawn_impl(Coro::Task<void> task)
{
co_await schedule_on(executor);
co_await std::move(task);
}
} // namespace Detail
inline void spawn(Executor& executor, Coro::Task<void> task)
{
Detail::spawn_impl(executor, std::move(task));
Detail::DetachedTask detached = Detail::spawn_impl(std::move(task));
executor.post(detached.handle);
}
struct ScheduleStatusAwaiter {