Experiment: make cross-thread run/status flags std::atomic (#3798 batches A/B)#3800
Draft
mcfnord wants to merge 1 commit into
Draft
Experiment: make cross-thread run/status flags std::atomic (#3798 batches A/B)#3800mcfnord wants to merge 1 commit into
mcfnord wants to merge 1 commit into
Conversation
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>
softins
reviewed
Jul 17, 2026
| CSocket* pSocket; | ||
| bool bRun; | ||
| CSocket* pSocket; | ||
| std::atomic<bool> bRun; |
Member
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.
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 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