Concurrent computing: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
(→{{header|Tcl}}: +SML) |
||
Line 1,849: | Line 1,849: | ||
</pre> |
</pre> |
||
=={{header|Standard ML}}== |
|||
Works with PolyML |
|||
<lang Standard ML>structure TTd = Thread.Thread ; |
|||
structure TTm = Thread.Mutex ; |
|||
val threadedStringList = fn tasks:string list => |
|||
let |
|||
val mx = TTm.mutex () ; |
|||
val taskstore = ref tasks ; |
|||
fun makeFastRand () = Real.rem (Time.toReal (Time.now ()),1.0) |
|||
val doTask = fn () => |
|||
let |
|||
val mytask : string ref = ref "" ; |
|||
in |
|||
( TTm.lock mx ; mytask := hd ( !taskstore ) ; taskstore:= tl (!taskstore) ; TTm.unlock mx ; |
|||
Posix.Process.sleep (Time.fromReal (makeFastRand ())) ; |
|||
TTm.lock mx ; print ( !mytask ^ "\n") ; TTm.unlock mx ; |
|||
TTd.exit () |
|||
) |
|||
end |
|||
in |
|||
List.tabulate ( length tasks , fn i => TTd.fork (doTask , []) ) |
|||
end ; |
|||
</lang> |
|||
call |
|||
threadedStringList [ "Enjoy","Rosetta","Code" ]; |
|||
Rosetta |
|||
Code |
|||
Enjoy |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
Assuming that "random" means that we really want the words to appear in random (rather then "undefined" or "arbitrary") order: |
Assuming that "random" means that we really want the words to appear in random (rather then "undefined" or "arbitrary") order: |