3.4 KiB
3.4 KiB
Async OperationState, ResumeTicket, TaskScope, and Bounded Executor Lanes
Task ID: M-ASYNC-02, M-ASYNC-03 Phase: P1 Status: APPROVED Contracts: C-01, C-04, C-06, C-07
1. Context and baseline
src/Async/module.cmake currently depends only on LogState, while include/Void/Async/Executor.hpp provides only void-returning post(), ManualExecutor, schedule_on, and fire-and-forget spawn(). Async lacks structured admission control, race-free backend completion vs cancellation settlement, completion-lane backpressure bypass, and structured TaskScope join/cancellation/exception ownership.
2. Deliverables
- Updated
src/Async/module.cmakedeclaringINTERNAL_DEPS Functional Time LogState. - New
include/Void/Async/Operation.hpp:OperationOptions,AdmissionError,AsyncErrorCode(kAsyncErrorDomain),make_async_error,DomainOutcomeKind,ResumeTicket, andOperationStatemanaging combinedstd::stop_source, atomicbackend_refs, single-winner CAS terminal state, and post-backend-release continuation resumption outside locks. - Upgraded
include/Void/Async/Executor.hpp: keeps 1.xpost/ManualExecutor/schedule_on/spawnworking while addingtry_post,post_completion(reserved completion lane),is_executor_thread(), boundedManualExecutorqueue capacity, and cancellable clock-awareschedule_on(executor, options, clock). - New
include/Void/Async/TaskScope.hpp:TaskScopeOptions,JoinHandle, reserve-then-transferTaskScope::spawn(preservingTask<void>on admission failure),request_stop,co_await join(),join_blocking()withself_joindetection,join_pumping, andDetachedOwner. - Tests in
tests/standalone/Async/OperationScope.cpp.
3. Exact files and interfaces
src/Async/module.cmakeinclude/Void/Async/Operation.hppinclude/Void/Async/Executor.hppinclude/Void/Async/TaskScope.hpptests/standalone/Async/OperationScope.cpp
4. Edge cases
- Failed
TaskScope::spawn(full or stopped) does not consume or destroy caller'sCoro::Task<void>. - Concurrent backend commit vs
std::stop_tokenfiring resolves to exactly one terminal outcome, releases backend references before resuming continuation outside locks, and supports synchronous completion without double-resume. - Reserved
post_completionsucceeds even when normal submission queue capacity is saturated. join_blocking()called from the associated executor thread detectsself_joinrather than deadlocking.- Concurrent cancellation/completion/join stress passes cleanly under Debug TSan and ASan/UBSan.
5. Acceptance criteria
OperationScope*,Executor*,Coro*, andThreadPool*tests pass under RelWithDebInfo-Werror, ASan+UBSan, and Debug TSan (-DVOID_ENABLE_TSAN=ON).
6. Verification commands
dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-w4a-async -G Ninja -DVOID_ENABLED_MODULES="Async;Testing" -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-w4a-async && /tmp/void-w4a-async/tests/VoidTests --filter "OperationScope*|Executor*|Coro*" && ctest --test-dir /tmp/void-w4a-async --output-on-failure --timeout 60'
dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-w4a-async-tsan -G Ninja -DCMAKE_BUILD_TYPE=Debug -DVOID_ENABLED_MODULES="Async;Testing" -DVOID_ENABLE_TSAN=ON -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-w4a-async-tsan && /tmp/void-w4a-async-tsan/tests/VoidTests --filter "OperationScope*|Executor*|ThreadPool*"'