Events: Difference between revisions

Content added Content deleted
(Updated to compile with Nim 1.4: replaced "wait x" by "wait(addr x)".)
(Replaced "cpuTime" by "getTime" to get elapsed time and take sleeping time in account.)
Line 703: Line 703:
<lang nim>import locks
<lang nim>import locks
from os import sleep
from os import sleep
from times import cpuTime
import times
from strformat import fmt
from strformat import fmt


Line 714: Line 714:
proc waiting {.thread.} =
proc waiting {.thread.} =
echo "spawned waiting proc"
echo "spawned waiting proc"
let start = cpuTime()
let start = getTime()
cond.wait lock
cond.wait lock
echo fmt"thread ended after waiting: {cpuTime() - start} seconds."
echo fmt"thread ended after waiting {getTime() - start}."


proc main =
proc main =
Line 737: Line 737:
spawned waiting proc
spawned waiting proc
send signal/event notification
send signal/event notification
thread ended after waiting: 1.001 seconds.</pre>
thread ended after waiting 1 second, 61 microseconds, and 311 nanoseconds.</pre>


=={{header|Oforth}}==
=={{header|Oforth}}==