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.




/**
 Concurrent computing, in Neko
*/
 
var thread_create = $loader.loadprim("std@thread_create", 2);
 
var subtask = function(message) {
  $print(message, "\n");
}
 
/* The thread functions happen so fast as to look sequential */
thread_create(subtask, "Enjoy");
thread_create(subtask, "Rosetta");
thread_create(subtask, "Code");
 
/* slow things down */
var sys_sleep = $loader.loadprim("std@sys_sleep", 1);
var random_new = $loader.loadprim("std@random_new", 0);
var random_int = $loader.loadprim("std@random_int", 2);
 
var randomsleep = function(message) {
  var r = random_new();
  var sleep = random_int(r, 3);
  sys_sleep(sleep);
  $print(message, "\n");
}
 
$print("\nWith random delays\n");
thread_create(randomsleep, "Enjoy");
thread_create(randomsleep, "Rosetta");
thread_create(randomsleep, "Code");
 
/* Let the threads complete */
sys_sleep(4);