Skip to content

Instantly share code, notes, and snippets.

@iaveryanov
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iaveryanov/9939419 to your computer and use it in GitHub Desktop.
Save iaveryanov/9939419 to your computer and use it in GitHub Desktop.
private boolean decTillZero(AtomicLong counter) {
while (true) {
long current = counter.get();
if (current == 0) {
return false;
}
long next = current - 1;
if (counter.compareAndSet(current, next)) {
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment