Experiment: make cross-thread run/status flags std::atomic (#3798 batches A/B)#3800
Experiment: make cross-thread run/status flags std::atomic (#3798 batches A/B)#3800mcfnord wants to merge 1 commit into
Conversation
| CSocket* pSocket; | ||
| bool bRun; | ||
| CSocket* pSocket; | ||
| std::atomic<bool> bRun; |
There was a problem hiding this comment.
Note that this one is already addressed as part of #3788, which is just awaiting a second approval.
|
Also you need to fix the coding style violations |
The socket, high-precision timer and sound threads are stopped by a plain bool written from another thread, and the jitter-buffer status flags are written and read/reset from different threads. Convert these six flags to std::atomic<bool>: - CSocketThread::bRun - CHighPrecisionTimer::bRun (Mac/Linux variant) - CSoundBase::bRun - CSoundBase::bCallbackEntered - CSocket::bJitterBufferOK - CClient::bJitterBufferOK The read-and-reset functions now use exchange() so a "not OK" written between a separate read and reset can no longer be lost. Addresses batches A and B of jamulussoftware#3798. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
3903e84 to
e12cd8d
Compare
This error class should be prevented when help about the formatting rules (or a link to the rules) appears in AGENTS.md. I don't see your draft of AGENTS.md as a PR, and I think you said you'd be providing one, so I remember yesterday my agent linked to my draft in a comment. For now, my CLAUDE.md has added the following guidance, including the note that eventually this will reach the AGENTS.md file when it exists: Upstream PRs (jamulussoftware/jamulus)Upstream Style, before every commit:
|
This follows up on the discussion in #3786 and covers batches A and B of the audit in #3798 — the thread-lifecycle
bRunflags and the jitter-buffer status flags. Offering it as an experiment: it is the least invasive slice of #3798, intended to establish thestd::atomicpattern in the codebase and let us observe it through CI and normal use before deciding whether the more involved findings (C–F) are worth touching.What changes
Six members become
std::atomic<bool>, keeping plain operator syntax at every call site (per the conclusion in #3786 that the overloaded operators are simplest, and the default sequentially-consistent operations cost nothing at these rates):CSocketThread::bRunStop())CHighPrecisionTimer::bRun(Mac/Linux variant)Start()/Stop())IsRunning()CSoundBase::bRunStart()/Stop())CSoundBase::bCallbackEnteredCSocket::bJitterBufferOKCClient::bJitterBufferOKThe only non-declaration change: the two
GetAndResetbJitterBufferOKFlag()functions now useexchange ( true )instead of a separate read and reset. Behavior is the same, and it closes a small lost-update window — a "not OK" written by the socket/sound thread between the read and the reset used to be dropped silently.Behavior
No intended behavior change. On x86 these compile to essentially the same instructions; the difference is that the compiler may no longer cache the flag across loop iterations, and on weakly-ordered CPUs (Apple Silicon, Android, ARM Linux servers) the cross-thread store is guaranteed to become visible and correctly ordered.
Tested
Stop()paths of the socket and timer threads.🤖 Generated with Claude Code