-
Notifications
You must be signed in to change notification settings - Fork 406
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
AtomicCounter release/acquire methods #315
base: master
Are you sure you want to change the base?
AtomicCounter release/acquire methods #315
Conversation
60fde98
to
a8cce93
Compare
@@ -330,27 +435,51 @@ public boolean compareAndSet(final long expectedValue, final long updateValue) | |||
} | |||
|
|||
/** | |||
* Get the latest value for the counter with volatile semantics. |
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 have removed 'latest' because it implies that you will see the latest value. This isn't true. A correctly synchronized program will only show sequential consistent executions, and for sequential consistency, the real time order doesn't need to respected. For that you need linearizability.
The JVM will guarantee visibility, so it will promise that a value is seen eventually (but not immediately).
Unfortunately 'latest' is frequently mentioned even by JMM experts, but it isn't correct.
To make this PR less contentious.
For all ordered methods, there is now a release variant. The ordered method will call the release version, so there is a slight performance penalty to pay.
Also getAcquire has been added since that normally is used in combination with a release method.