Last active
May 26, 2016 15:00
-
-
Save thomasnield/a3f7981ea447e0c049ba5943afa44fb8 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
import java.util.concurrent.atomic.AtomicBoolean | |
import kotlin.concurrent.thread | |
fun main(args: Array<String>) { | |
val queue = SingleBlockingQueue<Int>() | |
val isDone = AtomicBoolean(false) | |
thread { | |
for (i in 1..100) { | |
queue.offer(i) | |
} | |
isDone.set(true) | |
} | |
thread { | |
while (!isDone.get()) { | |
println(queue.take()) | |
Thread.sleep(100) //retarding the next take() will result in last item getting skipped | |
} | |
} | |
Thread.sleep(10000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment