Created
December 13, 2012 13:10
-
-
Save nitsanw/4276304 to your computer and use it in GitHub Desktop.
Catchup
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
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