Skip to content

Instantly share code, notes, and snippets.

@nitsanw
Created December 13, 2012 13:10
Show Gist options
  • Save nitsanw/4276304 to your computer and use it in GitHub Desktop.
Save nitsanw/4276304 to your computer and use it in GitHub Desktop.
Catchup
final class Producer implements Runnable {
public void run() {
latch.countDown();
for (long l = 0; l < ITERATIONS; l++) {
values[(int) l] = l;
producerIndex.set(l);
}
}
}
final class Consumer implements Runnable {
public void run() {
latch.countDown();
while (consumerIndex < ITERATIONS - 1) {
long l = producerIndex.get();
while (consumerIndex < l) {
consumerIndex++;
if (values[(int) l] != l)
throw new RuntimeException();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment