-
Notifications
You must be signed in to change notification settings - Fork 735
Fix release fence ordering in inner_enqueue() to prevent size_approx() race on AArch64 #172
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // ©2013-2020 Cameron Desrochers. | ||
| // ©2013-2020 Cameron Desrochers. | ||
| // Distributed under the simplified BSD license (see the license file that | ||
| // should have come with this header). | ||
|
|
||
|
|
@@ -619,6 +619,13 @@ class MOODYCAMEL_MAYBE_ALIGN_TO_CACHELINE ReaderWriterQueue | |
| newBlock->tail = newBlock->localTail = 1; | ||
|
|
||
| newBlock->next = tailBlock_->next.load(); | ||
|
|
||
| // Publish all writes to *newBlock before it becomes reachable via either | ||
| // tailBlock_->next (walked by size_approx() and other chain traversals) | ||
| // or tailBlock itself (used by try_dequeue). Without this fence, on | ||
| // weakly-ordered architectures (e.g. AArch64) a reader could observe the | ||
| // updated `next` pointer before seeing newBlock's initialized fields. | ||
| fence(memory_order_release); | ||
| tailBlock_->next = newBlock; | ||
|
|
||
| // Might be possible for the dequeue thread to see the new tailBlock->next | ||
|
|
@@ -627,7 +634,6 @@ class MOODYCAMEL_MAYBE_ALIGN_TO_CACHELINE ReaderWriterQueue | |
| // case where it could try to read the next is if it's already at the tailBlock, | ||
| // and it won't advance past tailBlock in any circumstance). | ||
|
|
||
| fence(memory_order_release); | ||
| tailBlock = newBlock; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we still need a release fence before setting
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeap, that is right. We need to guarantee that |
||
| } | ||
| else if (canAlloc == CannotAlloc) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment was to justify the previous placement of the fence, and can be removed, since it clearly missed a case in its reasoning :)