Files

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.cmake declaring INTERNAL_DEPS Functional Time LogState.
  • New include/Void/Async/Operation.hpp: OperationOptions, AdmissionError, AsyncErrorCode (kAsyncErrorDomain), make_async_error, DomainOutcomeKind, ResumeTicket, and OperationState managing combined std::stop_source, atomic backend_refs, single-winner CAS terminal state, and post-backend-release continuation resumption outside locks.
  • Upgraded include/Void/Async/Executor.hpp: keeps 1.x post/ManualExecutor/schedule_on/spawn working while adding try_post, post_completion (reserved completion lane), is_executor_thread(), bounded ManualExecutor queue capacity, and cancellable clock-aware schedule_on(executor, options, clock).
  • New include/Void/Async/TaskScope.hpp: TaskScopeOptions, JoinHandle, reserve-then-transfer TaskScope::spawn (preserving Task<void> on admission failure), request_stop, co_await join(), join_blocking() with self_join detection, join_pumping, and DetachedOwner.
  • Tests in tests/standalone/Async/OperationScope.cpp.

3. Exact files and interfaces

  • src/Async/module.cmake
  • include/Void/Async/Operation.hpp
  • include/Void/Async/Executor.hpp
  • include/Void/Async/TaskScope.hpp
  • tests/standalone/Async/OperationScope.cpp

4. Edge cases

  • Failed TaskScope::spawn (full or stopped) does not consume or destroy caller's Coro::Task<void>.
  • Concurrent backend commit vs std::stop_token firing resolves to exactly one terminal outcome, releases backend references before resuming continuation outside locks, and supports synchronous completion without double-resume.
  • Reserved post_completion succeeds even when normal submission queue capacity is saturated.
  • join_blocking() called from the associated executor thread detects self_join rather than deadlocking.
  • Concurrent cancellation/completion/join stress passes cleanly under Debug TSan and ASan/UBSan.

5. Acceptance criteria

  • OperationScope*, Executor*, Coro*, and ThreadPool* 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*"'