added system.running for threads

This commit is contained in:
Araq
2011-08-11 21:22:23 +02:00
parent a1cdd6e7ff
commit 7ad5cab17e
3 changed files with 14 additions and 10 deletions

View File

@@ -290,6 +290,10 @@ template ThreadProcWrapperBody(closure: expr) =
# However this is doomed to fail, because we already unmapped every heap
# page!
# mark as not running anymore:
t.emptyFn = nil
t.dataFn = nil
{.push stack_trace:off.}
when defined(windows):
proc threadProcWrapper[TMsg](closure: pointer): int32 {.stdcall.} =
@@ -300,6 +304,10 @@ else:
ThreadProcWrapperBody(closure)
{.pop.}
proc running*[TMsg](t: TThread[TMsg]): bool {.inline.} =
## returns true if `t` is running.
result = t.emptyFn == nil and t.dataFn == nil
proc joinThread*[TMsg](t: TThread[TMsg]) {.inline.} =
## waits for the thread `t` to finish.
when hostOS == "windows":