mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 03:32:32 +00:00
committed by
Andreas Rumpf
parent
156bd29c68
commit
e20af5cec6
@@ -465,17 +465,22 @@ proc handle*[TArg](t: Thread[TArg]): SysThread {.inline.} =
|
||||
result = t.sys
|
||||
|
||||
when hostOS == "windows":
|
||||
const MAXIMUM_WAIT_OBJECTS = 64
|
||||
|
||||
proc joinThread*[TArg](t: Thread[TArg]) {.inline.} =
|
||||
## waits for the thread `t` to finish.
|
||||
discard waitForSingleObject(t.sys, -1'i32)
|
||||
|
||||
proc joinThreads*[TArg](t: varargs[Thread[TArg]]) =
|
||||
## waits for every thread in `t` to finish.
|
||||
var a: array[0..255, SysThread]
|
||||
sysAssert a.len >= t.len, "a.len >= t.len"
|
||||
for i in 0..t.high: a[i] = t[i].sys
|
||||
discard waitForMultipleObjects(t.len.int32,
|
||||
cast[ptr SysThread](addr(a)), 1, -1)
|
||||
var a: array[MAXIMUM_WAIT_OBJECTS, SysThread]
|
||||
var k = 0
|
||||
while k < len(t):
|
||||
var count = min(len(t) - k, MAXIMUM_WAIT_OBJECTS)
|
||||
for i in 0..(count - 1): a[i] = t[i + k].sys
|
||||
discard waitForMultipleObjects(int32(count),
|
||||
cast[ptr SysThread](addr(a)), 1, -1)
|
||||
inc(k, MAXIMUM_WAIT_OBJECTS)
|
||||
|
||||
else:
|
||||
proc joinThread*[TArg](t: Thread[TArg]) {.inline.} =
|
||||
|
||||
Reference in New Issue
Block a user