Skip to content

ariadne: nav compute-pool async demo + app.compute_async (item 2) - #462

Merged
transfix merged 1 commit into
masterfrom
design/ariadne-nav-computepool-demo
Sep 28, 2026
Merged

transfix merged 1 commit into
masterfrom
design/ariadne-nav-computepool-demo

Conversation

@transfix

Copy link
Copy Markdown
Owner

Implements item 2 of the Ariadne roadmap — the cross-thread async story, end to end: a host intrinsic runs a nav step on the compute pool off the render thread and hands the result back through the one thread-safe seam (exec_scheduler().post_message), waking a parked .ari (msg-recv "nav.done") action that threads the value into state. The UI never blocks while the step runs.

What lands

  • cvc::app::compute_async(n, fn, on_done, priority) (app.h/app.cpp) — runs fn(i) over [0,n) as a data-parallel fan-out on computePool() off the caller's thread (a background startThreadPooled(wait=false) worker owns the blocking parallel_for), then calls on_done on that worker. This is the async-schedule-safe way to drive a parallel_for from the scheduler/host thread: an Ariadne program on: / host intrinsic runs inline in Runtime::drain() and must not block, so it calls compute_async and returns immediately; on_done typically posts the result. parallel_for stays a plain blocking barrier — this only moves the wait off the caller's thread (it does not de-block the barrier).
  • src/cvcGL/examples/nav_compute.{cpp,ari} — a new ari-based demo. The "Run nav step" button is a program on: that calls (nav-step-async) then parks on (msg-recv "nav.done"); status flips running → done across a real cross-thread gap. The host binds nav-step-async via register_action_intrinsics + app.compute_async. Existing demos are untouched (additive-demos policy) — only a new add_executable block is added to CMakeLists.txt.

Tests (headless, no ImGui/GL)

  • AppTest.ComputeAsyncRunsFanOutOffThreadThenCallsOnDone — the helper, deterministic via a std::promise.
  • AriadneAction.IntrinsicRunsNavStepOnComputePoolAndWakesMsgRecv — the full intrinsic → compute pool → post_message → msg-recv wake → state write round-trip. msg-recv pops any already-buffered pending message before parking, so it is race-free regardless of whether the worker posts before or after the park.

Local: app_test 77 + ariadne_runtime_test 93 green; nav_compute builds (imgui-OFF stub) and boots headlessly (--offscreen) parsing the .ari cleanly. clang-format clean, no >100-col lines.

Design decision (documented in the walk + this PR)

parallel_for is intentionally a fork-join barrier; async-safety comes from placement (run it on a background pool worker), not from de-blocking the primitive. Verified via the investigation that post_message is the thread-safe MPSC ingress and drain_ingress delivers on the host thread — so a pool worker's completion needs no manual marshalling.

Follow-up (next PR, already agreed)

Message channels are currently global (not chrooted to the document prefix) — an isolation gap vs. state's per-document chroot (§4.7/§11.4). The next change scopes channels to the chroot and lets them follow §12 link holes (private-by-prefix + explicit cross-scope via a mount's link:). After it lands, this demo's intrinsic resolves "nav.done" through ictx.root_path — a one-line update. Current tests use prefix "" so they're unaffected.

Not compiled locally

The build here is CVC_ENABLE_IMGUI=OFF, so the interactive window is exercised only by CI's recipe build (the stub compiles + boots locally). The async logic is fully covered by the headless gtests.

…tem 2)

Proves the cross-thread async story end to end: a host intrinsic runs a nav
step on the compute pool OFF the render thread and hands the result back through
the one thread-safe seam (exec_scheduler().post_message), waking a parked .ari
(msg-recv "nav.done") action that threads the value into state — the UI never
blocks while the step runs.

- cvc::app::compute_async(n, fn, on_done, priority) — run fn(i) over [0,n) as a
  data-parallel fan-out on computePool() OFF the caller's thread (a background
  startThreadPooled worker owns the blocking parallel_for), then call on_done on
  that worker. The async-schedule-safe way to drive a parallel_for from the
  scheduler/host thread (an Ariadne program on:/intrinsic runs inline in drain()
  and must not block): the caller returns immediately; on_done typically posts
  the result. parallel_for stays a plain blocking barrier — this only moves the
  wait off the caller's thread.
- src/cvcGL/examples/nav_compute.{cpp,ari} — a NEW ari-based demo (existing demos
  untouched, per the additive-demos policy): the "Run nav step" button is a
  program on: that calls (nav-step-async) then parks on (msg-recv "nav.done").
  The host binds nav-step-async via register_action_intrinsics + app.compute_async.
- Tests (headless, no ImGui/GL): AppTest.ComputeAsync* (the helper, deterministic
  via a promise) and AriadneAction.IntrinsicRunsNavStepOnComputePoolAndWakesMsgRecv
  (the full intrinsic -> compute pool -> post_message -> msg-recv wake round-trip;
  msg-recv pops any pending message before parking, so it is race-free either
  ordering). app_test 77 + ariadne_runtime_test 93 green locally.

NB message channels are currently GLOBAL (not chrooted to the document prefix);
scoping them to the chroot + link path is the next change, after which this
demo's intrinsic resolves "nav.done" through ictx.root_path (a one-line update).
@transfix
transfix merged commit d7da6a0 into master Sep 28, 2026
13 checks passed
@transfix
transfix deleted the design/ariadne-nav-computepool-demo branch October 29, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant