Concurrent computing: Difference between revisions

m
Updated code to match task, removed output as defined by task.
m (Removed output as defined by task, updated code to match task)
m (Updated code to match task, removed output as defined by task.)
Line 1,042:
 
=={{header|Neko}}==
<lang ActionScript>/**var thread_create = $loader.loadprim("std@thread_create", 2);
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, "EnjoyA");
thread_create(randomsleep, "RosettaB");
thread_create(randomsleep, "CodeC");
 
/* Let the threads complete */
sys_sleep(4);</lang>
 
{{out}}
<pre>prompt$ nekoc threading.neko
prompt$ neko threading
Enjoy
Rosetta
Code
 
With random delays
Rosetta
Enjoy
Code</pre>
 
=={{header|Nim}}==