Skip to content

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

Merged
nyanpasu64 merged 1 commit intomasterfrom
fix-spsc-data-race
Jun 23, 2022
Merged

Fix mostly-theoretical data race when popping from SPSC queues#149
nyanpasu64 merged 1 commit intomasterfrom
fix-spsc-data-race

Conversation

@nyanpasu64
Copy link
Copy Markdown
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