Created
June 24, 2020 03:39
-
-
Save softberries/8759c2dba0b8592c7e81e574b599c651 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Atomically increments by one the current value. | |
* | |
* @return the updated value | |
*/ | |
public final int incrementAndGet() { | |
for (;;) { | |
int current = get(); | |
int next = current + 1; | |
if (compareAndSet(current, next)) | |
return next; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment