Created
July 8, 2016 19:59
-
-
Save bluestreak01/4b374d1e055ac3fd7a80c05bfdf1e11d 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
while (true) { | |
// consumer receives next cursor | |
// if cursor is >= 0 - thread can use it as ring queue index | |
// if cursor == -1 - ring queue is full, thread has a choice to do something else | |
// if cursor == -2 - there was CAS failure and thread can retry more eagerly | |
// for purpose of this test we busy loop regardless | |
long cursor = sequence.next(); | |
if (cursor < 0) { | |
continue; | |
} | |
int v = queue.get(cursor).value; | |
sequence.done(cursor); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment