Task

Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order.

Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.




// version 1.1.2
 
import java.util.concurrent.CyclicBarrier
 
class DelayedMessagePrinter(val barrier: CyclicBarrier, val msg: String) : Runnable {
    override fun run() {
        barrier.await()
        println(msg)
    }
}
 
fun main(args: Array<String>) {
    val msgs = listOf("Enjoy", "Rosetta", "Code")
    val barrier = CyclicBarrier(msgs.size)
    for (msg in msgs) Thread(DelayedMessagePrinter(barrier, msg)).start()
}