Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

pveentjer
Copy link
Contributor

@pveentjer pveentjer commented Jan 19, 2025

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.

@pveentjer pveentjer force-pushed the feature/AtomicCounter-memory-order branch from 60fde98 to a8cce93 Compare January 19, 2025 11:52
@pveentjer pveentjer changed the title AtomicCounter release/acquire improvements AtomicCounter release/acquire operations Jan 19, 2025
@pveentjer pveentjer changed the title AtomicCounter release/acquire operations AtomicCounter release/acquire methods Jan 19, 2025
@@ -330,27 +435,51 @@ public boolean compareAndSet(final long expectedValue, final long updateValue)
}

/**
* Get the latest value for the counter with volatile semantics.
Copy link
Contributor Author

@pveentjer pveentjer Jan 20, 2025

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant