Repository navigation
ariadne: nav compute-pool async demo + app.compute_async (item 2) - #462
Merged
Merged
Conversation
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) — runsfn(i)over[0,n)as a data-parallel fan-out oncomputePool()off the caller's thread (a backgroundstartThreadPooled(wait=false)worker owns the blockingparallel_for), then callson_doneon that worker. This is the async-schedule-safe way to drive aparallel_forfrom the scheduler/host thread: an Ariadne programon:/ host intrinsic runs inline inRuntime::drain()and must not block, so it callscompute_asyncand returns immediately;on_donetypically posts the result.parallel_forstays 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 programon:that calls(nav-step-async)then parks on(msg-recv "nav.done"); status flipsrunning → doneacross a real cross-thread gap. The host bindsnav-step-asyncviaregister_action_intrinsics+app.compute_async. Existing demos are untouched (additive-demos policy) — only a newadd_executableblock is added toCMakeLists.txt.Tests (headless, no ImGui/GL)
AppTest.ComputeAsyncRunsFanOutOffThreadThenCallsOnDone— the helper, deterministic via astd::promise.AriadneAction.IntrinsicRunsNavStepOnComputePoolAndWakesMsgRecv— the fullintrinsic → compute pool → post_message → msg-recv wake → state writeround-trip.msg-recvpops 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_computebuilds (imgui-OFF stub) and boots headlessly (--offscreen) parsing the.aricleanly. clang-format clean, no >100-col lines.Design decision (documented in the walk + this PR)
parallel_foris 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 thatpost_messageis the thread-safe MPSC ingress anddrain_ingressdelivers 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"throughictx.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.