Source
Edit
Wait groups for Nim.
Example:
import threading/waitgroups
var data: array[10, int]
var wg = createWaitGroup()
proc worker(i: int) =
data[i] = 42
wg.leave()
var threads: array[10, Thread[int]]
wg.enter(10)
for i in 0..<10:
createThread(threads[i], worker, i)
wg.wait()
for x in data:
assert x == 42
joinThreads(threads)
WaitGroup = object
-
A WaitGroup is a synchronization object that can be used to wait until all workers have completed.
Source
Edit
proc enter(b: var WaitGroup; delta: Natural = 1) {.inline, ...raises: [], tags: [],
forbids: [].}
-
Tells the WaitGroup that one or more workers (the delta parameter says how many) "entered", which means to increase the counter that counts how many workers to wait for.
Source
Edit
proc leave(b: var WaitGroup) {.inline, ...raises: [], tags: [], forbids: [].}
-
Tells the WaitGroup that one worker has finished its task.
Source
Edit
proc wait(b: var WaitGroup) {....raises: [], tags: [], forbids: [].}
-
Waits until all workers have completed.
Source
Edit