Skip to content

Instantly share code, notes, and snippets.

@enginebai
Created May 14, 2022 14:16
Show Gist options
  • Save enginebai/ba56161217d78c32880113a44427b4ab to your computer and use it in GitHub Desktop.
Save enginebai/ba56161217d78c32880113a44427b4ab to your computer and use it in GitHub Desktop.
object Worker {
var total = 0
fun accumulate() {
for (i = 0; i < 10000; i++) {
total = total + 1
}
}
fun doWork() {
for (j = 1; j <= 5; j++) {
val t = thread {
accumulate()
}
}
}
}
fun main() {
Worker.doWork()
println(Woker.total)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment