Source
Edit
Latch for Nim.
Example:
import sync/latch
var data: array[10, int]
var x: Latch
initLatch(x, 10)
proc worker(i: int) =
data[i] = 42
x.dec()
var threads: array[10, Thread[int]]
for i in 0..<10:
createThread(threads[i], worker, i)
x.wait()
for x in data:
assert x == 42
joinThreads(threads)
Latch = object
-
A Latch is a synchronization object that can be used to wait until all workers have completed.
Source
Edit
proc dec(x: var Latch) {....raises: [], tags: [], forbids: [].}
-
Tells the Latch that one worker has finished its task.
Source
Edit
proc wait(x: var Latch) {....raises: [], tags: [], forbids: [].}
-
Waits until all workers have completed.
Source
Edit