Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Concurrent-computing/Neko/concurrent-computing.neko
Normal file
34
Task/Concurrent-computing/Neko/concurrent-computing.neko
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue