Skip to content

Instantly share code, notes, and snippets.

@bluestreak01
Created July 8, 2016 19:59
Show Gist options
  • Save bluestreak01/4b374d1e055ac3fd7a80c05bfdf1e11d to your computer and use it in GitHub Desktop.
Save bluestreak01/4b374d1e055ac3fd7a80c05bfdf1e11d to your computer and use it in GitHub Desktop.
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