-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Rewrite of the AtomicReference #1615
Rewrite of the AtomicReference #1615
Conversation
@@ -69,6 +69,97 @@ public override void HeartBeat() | |||
{ | |||
_status.CompareAndSet(Status.Unknown, Status.Up); | |||
} | |||
|
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 class has used the old version with a value type, therefore I have copied the old version into this class.
Looks good to me. |
Looks good for GetAndSet, but CompareAndSet doesn't look thread safe, it should use Interlocked.CompareExchange. |
I reviewed the other atomic utils and noted this:
|
@JeffCyr The problem is that CompareExchange doesn't return a bool but rather the initial value. So would this be thread safe or is the equal operation not thread safe again?
Should I add the other classes to this PR as well? |
@Silv3rcircl3 It is thread-safe if you compare with the expected original value var previous = Interlocked.CompareExchange(ref atomicValue, newValue, expected);
return Object.ReferenceEquals(previous, expected); I think it's safer to compare the reference explicitly with |
@JeffCyr alright, thx for the info! |
We'll merge this in once @JeffCyr's comments are addressed |
ceea2dc
to
e36e100
Compare
@JeffCyr @Aaronontheweb updated. |
e36e100
to
fb7ef18
Compare
40b043d
to
e031685
Compare
cc @Aaronontheweb how do we fix the above? |
It's working locally, don't know why it doesn't work with the CI server... |
@Silv3rcircl3 could be, what happens if you revert that line and push it here again? |
e031685
to
dc0f261
Compare
that's it... will also update my other PR's |
👍 |
Going to merge this one in |
Rewrite of the AtomicReference
Based on the gitter discussion I have rewritten the AtomicReference based on the DotNetty version.