-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Add Atomic{Ptr} support and tests #33869
Conversation
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.
This is awesome. Thanks for doing this, Dillon! :) Looking forward to it!
This will probably also need NEWS as well, I would think, but you may want to wait for someone else to confirm that.
3fe16db
to
87aa6f9
Compare
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 defined atomic_add!/sub!(::Atomic{Ptr}, ::Integer)
separately since the signature is different enough (everything else follows the pattern (::Atomic{V}, V)
).
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.
:) Thanks for doing this Dillon, it looks good to me!
(Other than the annoying thing I just noticed about the "logical ops". i've left a comment.)
I think this would be ready for review from a maintainer.
I think this is ready for review. The build error looks unrelated. |
@vtjnash, are you the right person to review this? |
I can remove the logical ops defined on |
I went ahead and excluded defining the logical operations on |
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.
Thanks, looks great!
Bump |
|
||
# Note: atomic_cas! succeeded (i.e. it stored "new") if and only if the result is "cmp" | ||
if typ <: Integer | ||
@eval atomic_cas!(x::Atomic{$typ}, cmp::$typ, new::$typ) = | ||
if typ <: Union{Integer, Ptr} |
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.
This should probably be typ <: Integer || typ <: Ptr
. Otherwise it includes the type Union{Integer, Ptr}
.
Welcome, @dillondaudert , and thanks for working on this. This looks basically correct, but I'm not sure what the use cases are. #29943 asks for it for implementing lock-free data structures, but I doubt it's actually useful for that since |
Could you elaborate your thoughts on why not being tracked by the GC makes atomic I assumed since |
I could maybe imagine this being useful for something like Blobs.jl, making
use of the atomic add/subtract. But yeah, otherwise simple pointer
assignment is of course already atomic. Maybe we would use compare and swap
in something like Blobs as well?
I admit I haven't thought about it too much.
Definitely agree with Jeff's assessment that this alone won't be terribly
useful for lock-free datastructures. It would probably be most useful to
just support arbitrary types, with separate support for stack vs heap
allocated types?
…On Wed, Dec 18, 2019, 11:18 AM Dillon Daudert ***@***.***> wrote:
Could you elaborate your thoughts on why not being tracked by the GC makes
atomic Ptr not useful for lock-free data structures? I admit I don't know
all the subtleties and consequences around that.
I assumed since Ptr existed at all, it would be useful to have atomic
operations for it. If that's not the case, should instead they be defined
for Ref? I thought I read someone propose that in an issue at some point.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#33869?email_source=notifications&email_token=AKSS5LGGPWD2LJDPOBLPRZ3QZG2RNA5CNFSM4JOHGT6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHE565A#issuecomment-566878068>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKSS5LEJKRBBHDCRMHMGK3TQZG2RNANCNFSM4JOHGT6A>
.
|
No, it isn't. Yes, we likely also want this for |
It's unclear exactly what you intended to mean here. The simple assignment isn't "atomic" because that's not a property of the assignment but of the serializing side-effects that occur simultaneously (in the compiler and/or hardware). OTOH, it's pretty much unheard of for a processor do have a cache line smaller than a pointer word size, so the write of a pointer-sized word to an address with valid alignment is usually free of data races (torn writes). It's important to distinguish though that the Julia
Yes, but maybe worth clarifying that's not what this PR does. It's been my goal for some time now to provide new |
I'd be happy to help get proper atomic (pointer) operations implemented in Julia. At this point, I don't believe I'm familiar enough with |
This remains an operation we should have though? |
This defines the following atomic operations on pointers via
Atomic{Ptr}
:Fixes #29943, and possibly addresses #32455.
This still needs NEWS.