Skip to content

Release epoch registry while waiting - #159

Open
mark0-cn wants to merge 1 commit into
jonhoo:mainfrom
mark0-cn:codex/release-epochs-while-waiting
Open

Release epoch registry while waiting#159
mark0-cn wants to merge 1 commit into
jonhoo:mainfrom
mark0-cn:codex/release-epochs-while-waiting

Conversation

@mark0-cn

Copy link
Copy Markdown

Summary

  • snapshot registered epoch counters under the registry mutex
  • release the registry mutex before waiting for readers
  • reacquire it only for the pointer swap and next epoch snapshot
  • add deterministic and Loom coverage for handle creation while a writer waits

Root cause

publish and writer teardown held the epoch-registry mutex throughout the reader wait loop. Creating or dropping a ReadHandle needs the same mutex. An active reader that tried to clone its handle could therefore wait on the writer while the writer waited for that reader's guard to be dropped.

The writer now clones the registered Arc<AtomicUsize> values while holding the mutex and waits on that stable snapshot after releasing it. Readers registered after the previous swap only observe the current read pointer, so they do not need to delay reuse of the older write-side copy. The mutex is reacquired around the next swap to capture every handle needed by the following wait cycle.

This moves additional Arc clone/drop work to each writer wait in exchange for keeping handle registration live while a reader is pinned.

Validation

  • cargo test --offline
  • cargo fmt --all -- --check
  • RUSTFLAGS="--cfg loom" LOOM_MAX_PREEMPTIONS=3 cargo test --offline --release --test loom

@mark0-cn mark0-cn changed the title [codex] release epoch registry while waiting Release epoch registry while waiting Jul 27, 2026
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