Skip to content

core: world_clock_binding is thread-safe - #640

Merged
transfix merged 1 commit into
masterfrom
fix/world-clock-binding-threads
Oct 17, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/world-clock-binding-threads

Conversation

@transfix

Copy link
Copy Markdown
Owner

Why

world_clock locks itself and the state tree is thread-safe, but world_clock_binding's own members were not guarded:

  • the pending single steps;
  • the last step counter seen;
  • the requested mode;
  • the pause flag.

Calling request_steps() or pending_steps() from a UI thread while the frame thread runs drive() was a data race. The nav examples' step buttons and Ariadne host verbs call request_steps() that way.

What

  • Every public call (pull, push, drive, request_steps, pending_steps) takes a mutex.
  • drive() holds the lock across pull, advance, the requested steps and push. The step result it returns splices two advances, so it is never interleaved with another drive().
  • The class doc states the threading contract.

Verification (Windows, MSVC 2022, local cvcpkg prefix)

  • New test AppTest.ClockBindingTakesStepRequestsFromAnyThread: four threads request 1000 single steps while a fifth drives, and every request runs exactly once. It passed 4 runs in a row.
  • app_test 86/86, world_clock_test 49/49, and pycvc test_pycvc_world_clock.py pass.

The binding's own state (the pending single steps, the last step counter seen,
the requested mode and pause) was unguarded. world_clock locks itself and the
state tree is thread-safe, but request_steps() or pending_steps() from a UI
thread while the frame thread ran drive() was a data race. The nav examples'
step buttons and Ariadne host verbs call request_steps() that way.

Every public call now takes a mutex. drive() holds it across pull, advance,
the requested steps and push, so the result it returns, which splices two
advances, is never interleaved with another drive().

Test: ClockBindingTakesStepRequestsFromAnyThread. Four threads request 1000
single steps while a fifth drives; every request runs exactly once.
@transfix
transfix merged commit 806e8fe into master Oct 17, 2026
15 checks passed
@transfix
transfix deleted the fix/world-clock-binding-threads branch October 17, 2026 05:06
transfix added a commit that referenced this pull request Oct 17, 2026
Minor release. It carries:
- the world clock: lockstep and batch, followers, the sim.* binding, and nav
  on the clock (#629, #630, #631, #640);
- the units registry with SI <-> normalized-frame conversions (#632);
- cvc::physics with the Jolt backend (#641);
- the material trainer on the kinematic bicycle and its pycvc bindings
  (#642).
Bumps project(VERSION) 3.5.1 -> 3.6.0 and every cvcpkg recipe's
upstream_version to match. cvc_revision stays 1, per the recipe-version gate.
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