Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mostly-theoretical data race when popping from SPSC queues #149

Merged
merged 1 commit into from
Jun 23, 2022

Conversation

nyanpasu64
Copy link
Collaborator

The reader loses access to the front pointer as soon as it pops from the queue, since from that point onward, the writer can overwrite it with a new message. Instead the reader must finish using the pointer or copy the value out, before popping from the queue.

This bug terrifies me, that I managed to write it, not catch it reviewing my own code despite years of atomic threading experience, and only realized I made a mistake weeks later, when reading an paper (https://lmax-exchange.github.io/disruptor/files/Disruptor-1.0.pdf).

The reader loses access to the front pointer as soon as it pops from the
queue, since from that point onward, the writer can overwrite it with a
new message. Instead the reader must finish using the pointer or copy
the value out, before popping from the queue.

This bug terrifies me.
@nyanpasu64 nyanpasu64 force-pushed the fix-spsc-data-race branch from b2e2753 to 0e8c5b9 Compare June 23, 2022 12:11
@nyanpasu64 nyanpasu64 merged commit 3ff81e2 into master Jun 23, 2022
@nyanpasu64 nyanpasu64 deleted the fix-spsc-data-race branch June 23, 2022 13:04
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