Skip to content

Instantly share code, notes, and snippets.

@OlegDokuka
Created October 30, 2017 20:29
Show Gist options
  • Save OlegDokuka/d2b7262e77e0ad782404bd8a6239ccc2 to your computer and use it in GitHub Desktop.
Save OlegDokuka/d2b7262e77e0ad782404bd8a6239ccc2 to your computer and use it in GitHub Desktop.
for (;;) {
long currentDemand = demand.getAcquire(); // (1)
if (currentDemand == Long.MAX_VALUE) { // (2)
return;
}
long adjustedDemand = currentDemand + n;
if (adjustedDemand < 0L) { // (3)
adjustedDemand = Long.MAX_VALUE;
}
if (demand.compareAndSet(currentDemand, adjustedDemand)) { // (4)
if (currentDemand > 0) { // (5)
return;
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment