-
Notifications
You must be signed in to change notification settings - Fork 1.6k
std::atomic<std::shared_ptr>::wait
should compare control blocks
#3655
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3009cb0
`std::atomic<std::shared_ptr>::wait` should compare control blocks
fsb4000 de27d34
Merge branch 'main' into fix3602
fsb4000 d25fc84
add a test case
fsb4000 e1422f6
P1135R6_atomic_wait_vista hangs
fsb4000 8e9aa09
Merge branch 'main' into fix3602
StephanTLavavej bd5181b
`_Old_Rep` => `_Old_rep`
StephanTLavavej 9aeb9a0
`_Old` => `_Old_ptr` for clarity.
StephanTLavavej 506e941
Bugfix: Must share ownership or both be empty, even when owning the n…
StephanTLavavej 9716763
Add `const` to the `level` parameter.
StephanTLavavej 50943d9
Drop unnecessary braces.
StephanTLavavej dc0a582
Also test shared_ptrs that own the null pointer.
StephanTLavavej f837e8a
use growing timeout with __std_atomic_wait_direct
fsb4000 014a8c7
starting timeout = 16
fsb4000 07a6903
limit timeout to 1 million milliseconds (~17 minutes)
fsb4000 fc399ef
Comment units.
StephanTLavavej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
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.
No change requested; we should do this in a followup if at all to avoid resetting testing, since it's not a correctness issue. Should this be reordered as:
so we short-circuit when the core-local
_Rep == _Old_rep
isfalse
before potentially loading_Ptr
's cache line from some other core's data cache? (I suspect I understand cache coherence protocols just well enough to be dangerous.) Would any difference just be noise compared to the expense of_Repptr._Lock_and_load()
?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.
(Pulling in @AlexGuteniev to render an opinion and/or tell me how wrong I am 😄.)
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.
My vague understanding is that a relaxed load has no barriers, so it has no special costs. It would be fine to reorder, though, since the
.load
is at least a debug mode function call.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.
Aren't _Repptr and _Ptr in the same cache line? Sure, whatever they point to can be anywhere, but the pointers themselves are (as far as I can see) right beside each other.
(STL's comment sounds accurate, though.)
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 agree that they are always in the same cache line (it is really always, not just most of the time, because we over align to
alignas(2 * sizeof(void*))
). So from the cache perspective it does not matter.I agree also that eliminating debug mode call can be potentially beneficial.
Still I more like the original order, because we compare
_Rep == _Old_rep;
the very last thing, as close to wait as possible, so reduce the probability of resorting to timeout.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.
Considering _Rep is just a stack-local and the real load is on the line above, I can't quite follow your reasoning.
Uh oh!
There was an error while loading. Please reload this page.
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.
Hm, you are right, we done loading it into register at the same time anyway.
Then debug mode call saving could be the main decision factor here.
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.
Ah, I'd forgotten that we overalign - my cache coherence point is invalid. +1 to avoiding the call in debug compiles, though. We really want to minimize the time between load and check.