Skip to content

Instantly share code, notes, and snippets.

@thomasnield
Last active May 26, 2016 15:00
Show Gist options
  • Save thomasnield/a3f7981ea447e0c049ba5943afa44fb8 to your computer and use it in GitHub Desktop.
Save thomasnield/a3f7981ea447e0c049ba5943afa44fb8 to your computer and use it in GitHub Desktop.
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