Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
438 B
1
Indexable
Never
// @Volatile
var sum = 0;

fun main(args: Array<String>) {

        val thread1 = Thread {
            sum += 1;
        }
        val thread2 = Thread {
            sum += 2;
        }
        val thread3 = Thread {
            sleep(500)
            sum += 3;
        }
        val threadPool = arrayOf(thread1, thread2, thread3)

        threadPool.forEach { it.start() }
        threadPool.forEach { it.join() }
        println(sum)
}