Jump to content

Sorting algorithms/Sleep sort: Difference between revisions

(→‎{{header|Common Lisp}}: Add implementation)
Line 774:
 
=={{header|Nim}}==
Compile with <code>nim --threads:on c sleepsort</code>:
{{trans|C}}
<lang nim>import osthreadpool, posixos, strutils
 
proc run(time: int) =
var c = paramCount() + 1
sleep itime
while true:
dececho ctime
if c <= 1: break
if fork() == 0: break
 
parallel:
let i = parseInt paramStr c
for c in commandLineParams():
sleep i
spawn run parseInt c</lang>
echo i
var pid: cint = 0
discard wait(pid)</lang>
Usage:
<pre>$ ./sleepsort 5 1 3 2 11 6 4
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.