seq: fix possible race in seq_queue#8
Conversation
Fix possible race condition in seq_queue, where internal state was checked outside of a mutex. Fixes unit test failure in MacOS builds. Co-authored-by: google-labs-jules[bot]
|
Tested locally with macOS and arm64. I reproduced the failure 2/2 on |
|
One follow-up comment. The queue status helpers do not take |
|
I see the same behaviour as @anderslindho, and agree with his assessment of adding mutex locks. There's also the other question: why does this fail on MacOS but not on various linuces? |
Timing, I would think. These multi-core arms are just a whole bit faster. |
Let me check a bit further in the commit history. The original author(s?) were obviously very concerned about lock contention - the extra gymnastics that this PR removes are telling a story... In principle, read-only/status-only could be fine (off-by-one is ok in those cases), unless a race would produce crap data. I agree that locking would increase consistency and beauty - just wondering about the price tag. |
|
Commit ede72542 seq: complete redesign of broken queue adt
|
|
So the idea was to only lock in overflow - interesting. Nice article on the topic (not on locks, though): |
|
Indeed a nice article! I just noticed that there is a header comment that will need updating if we accept this fix (
Re costs, haven't we taken the brunt of them already with the change in this PR? |
|
I am sort of surprised at this. There is a mutex to block concurrent put/get when full which... fine? But why not concurrent gets or puts? Isn't that also a race condition? i.e. two puts at the same time would write to the same spot in memory with one of them being overwritten, no? |
See the comment that Anders mentioned: It's an attempt to implement a lock-free "SPSC" (single producer, single consumer) queue. |
|
Ah, I think I missed that it was a single producer and consumer. This does make more sense then. |
Fix possible race condition in seq_queue,
where internal state was checked outside of a mutex.
Fixes unit test failure in MacOS builds.
Co-authored-by: google-labs-jules[bot]