Repository navigation
state_exec locks L0: state-incr, state-cas and state-swap - #860
Merged
Merged
Conversation
… the locks deep workflow The state_exec lock work (docs/STATE_EXEC_LOCKS.md) adds code that runs on several threads, and no CI lane ran a race detector or an address checker. This lands them before any lock code, so that the races and leaks already in the tree get a baseline first. - ci.yml `sanitizers` (tsan, asan-ubsan): gcc's -fsanitize=thread, or -fsanitize=address,undefined, over libcvc itself (the cvcpkg deps stay uninstrumented), RelWithDebInfo, building only the targets it runs. It runs the existing suites that use threads (state_exec_scheduler, _async, _integration and _coordinator tests, ariadne_runtime_test, thread_pool_test, async_lane_test) and pycvc's exec scripts, with the sanitizer runtime preloaded into the interpreter. Suppressions go in .github/sanitizers/, each with a comment naming what it hides. Each lock phase appends its suites. - ci.yml's pull_request filter takes perf/** as well, so the lock phases' stacked drafts get the full set of jobs. - locks-deep.yml (daily, and by hand on a branch): a Release Linux build of the lock test targets, running their deep sizes. A dispatchable workflow must be on the default branch, so it lands first; on a ref without the lock tests it stops after the checkout.
…s, gate, and policy/locks sweep keys The state_exec lock phases decide their gates with the bench, and the design's gates need things compare could not do: two points of one run against each other, absolute bounds, a noise rule that refuses to judge a disturbed run, and a rule under which a drop in steps_total fails. tools/bench/state_exec_bench.py: - key_of leaves out a param at its implicit default (policy=rr, locks=none), so records from binaries without those keys still match. - compare --pair KEY=A:B compares the base's points at A with the candidate's at B, matched without KEY (both may be one run). - compare --max-noise P: a point noisier than P% is INCONCLUSIVE (exit 2, "repeat in a quieter window", never a pass). - compare --fail-on-change: any change beyond the noise fails, in either direction, for steps_total. - gate RUN --scenario --metric (--max|--min) [--stat] [--where] [--max-noise]: absolute bounds on one run. state_exec_bench: sched.single.*, flood.small and msg.* take two sweep keys, policy (rr, priority, priority_rr) and locks (none; the lock phases add private and shared, and a build without them skips such a point). A default run measures the same points as before, plus the two params at their defaults. tools/bench/test_state_exec_bench.py tests the rules on synthetic records; CTest runs it as state_exec_bench_tool_test when a working Python 3 is found.
Atomic single-node updates for the DSL's state-cas, state-swap and state-incr (docs/STATE_EXEC_LOCKS.md 4.4). Each compares, or computes, and assigns under one hold of the written node's mutex, then fires valueChanged and the parent's child signal with no lock held, only when the value changed. They write the node a read through a transparent link sees: a writable transparent link writes its target, as value(v) does. Unlike value(v), a transparent link that is not writable, or cannot be resolved, throws read_only_error rather than taking the write on the link node, so a compare and its write are always on the same node (gap G-7). Three non-virtual members and one private helper, so state.h stays source- and layout-compatible. pycvc wraps compareAndSetValue and exchangeValue; updateValue takes a std::function and is %ignore'd.
…-incr detail::read_number_text reads a token as the DSL does: the whole token as an int64, else as a double (strtod, for a token that may be one). The parser's parse_number_or_symbol now calls it, unchanged in behaviour, and state-incr will read a node's text with it, so both agree on what a number is (gap G-9).
The atomic natives of docs/STATE_EXEC_LOCKS.md 4.4, each one native call over cvc::state's atomic members: - (state-cas path expected new): #t when the value equalled `expected` and is now `new`. A nil expected matches an absent or "" node; an absent node is made only then. - (state-swap path new): the value it replaced, nil when absent or "". - (state-incr path [delta]): the new number. The node's text is read as a DSL number (detail::read_number_text); an absent or "" node is 0; anything else is a ValueError and the node is left as it was. int + int stays an int (an overflow is an ArithmeticError, gap G-11); otherwise the sum is a float, stored in its shortest round-trip form. Each resolves its path under the chroot and through a transparent link as state-get reads it; nil is "", a list or dict is a TypeError. A change fires watches and valueChanged once; an equal write fires nothing. Floats are written with std::to_chars where the library has it, else by detail::format_number_shortest_fallback, which writes to_chars's exact text (shortest round-trip digits, fixed or scientific, the exact digits of a whole number in fixed form). It is built everywhere, and a test checks it against to_chars byte for byte (gap G-10). Tests: state_exec_locks_test (new; the Atomics suite AT-1..AT-13 on both schedulers, AT-6's two-thread updateValue, the formatter against to_chars on a table and 20000 values; the locks_world fixture the lock phases reuse), and test_pycvc_state_exec_locks.py. Both join C0's sanitizer jobs.
state-incr and state-cas timed against state-set by the native.* method, on a node 1 or 4 levels down that starts at 0 and must end at n: op=set is (state-set P (+ i 1)), op=incr (state-incr P), op=cas (state-cas P i (+ i 1)), which succeeds and writes every time (gap G-8). Its gate, a paired one: incr and cas each at most 1.1x set in extra.ns_per_call (docs/STATE_EXEC_BENCH.md).
The developer guide's DSL state section gains state-incr, state-cas and state-swap: paths and links, absent nodes, nil, number text, signals, and which tool to use when. Ariadne's reactive lane does not bind them (they write). STATE_EXEC_LOCKS.md's status: L0 built.
…looks ASan's leak check failed state_exec_locks_test on 189 indirect leaks: default environments held by a closure bound in the scope it captured, a cycle only collect_cycles() frees. The tests step the schedulers by hand, so nothing ever collected. A gtest global environment now runs collect_cycles() at the end, when every world is gone, so the leak check sees only real leaks.
transfix
marked this pull request as ready for review
October 29, 2026 19:00
transfix
added a commit
that referenced
this pull request
Oct 29, 2026
transfix
added a commit
that referenced
this pull request
Oct 29, 2026
The project version and the cvcpkg recipe family move to 3.7.4. Every recipe is at cvc_revision 1 already, so none restarts. 3.7.4 carries the whole plant ledger on every plant (#876): plant_sample's vehicle contact and what each plant measures, the dynamic plants' building and vehicle contacts and attitude, nav_stats' vehicle_hits, cvc/nav/plant_ledger.h, and publish_nav_stats writing every item, n/a where a plant does not measure it. demo3's Ledger screen (CVC-DBG/cvcdbg#256) reads it. It also carries SDL3 owning cvcGL's onscreen window (#829), state_exec's state-incr, state-cas and state-swap (#860), and Ariadne's window fitting (#828) and room relay test counting (#867).
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.
This is phase L0 of the state_exec locks plan: the atomic natives of
docs/STATE_EXEC_LOCKS.mdsection 4.4.Stacking. The base is
perf/locks-base, which is master with #858 (C0, the sanitizer jobs) and #859 (B0, the bench's pair and gate rules) merged in. Once those two land, this retargets to master.What it adds
cvc::state:compareAndSetValue,exchangeValueandupdateValue.value(v)does.read_only_errorinstead ofvalue(v)'s write on the link node (gap G-7). So a compare and its write always see the same node.updateValuetakes astd::functionand is%ignored.(state-incr path [delta])returns the new number. An absent or empty node is 0; non-numeric text is aValueErrorand the node is left alone. int + int stays an int, and an overflow is anArithmeticError. Floats are stored in their shortest round-trip form.(state-cas path expected new)returns#tor#f. Anilexpected matches an absent or empty node.(state-swap path new)returns the old value,nilwhen absent or empty.state-getdoes.detail::read_number_text), shared by the parser andstate-incr(gap G-9).std::to_charsfallback for libc++ builds without floating-pointto_chars. It writesto_chars's exact text, and a test checks it byte for byte on every platform, against a table and 20,000 values that include powers of two (gap G-10).native.state_atomic:incrandcasagainstset, per call (gap G-8).STATE_API.md,ARIADNE.md(the reactive lane does not bind them) andSTATE_EXEC_BENCH.md.Tests
state_exec_locks_test(new): suiteAtomics, AT-1..AT-13 on both schedulers, plus argument errors and the DSL number rules.updateValuecalls; the count is exact. It is 10^4 underCVC_LOCKS_SANITIZER.FormatShortestFallback.locks_worldfixture: one intrinsics context per program, which L1 and later phases reuse.state_test:StateAtomicMembers.*, 10 cases.test_pycvc_state.pygains three cases;test_pycvc_state_exec_locks.pyis new.Run locally (Windows, MSVC, Release): every
state_exec_*suite,state_test,ariadne_runtime_testand the 11 pycvc state/exec tests pass, unchanged except for the new cases.state_exec_bench --smokepasses.Not done yet: the
native.state_atomicgate (incrandcasat most 1.1xset), and the regression A/B atlocks=noneagainst the base. Both need a quiet machine. Results will be posted here.