sync/latch

Search:
Group by:
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)

Types

Latch = object
A Latch is a synchronization object that can be used to wait until all workers have completed. Source   Edit  

Procs

proc `=copy`(dest: var Latch; source: Latch) {.error.}
Source   Edit  
proc `=dup`(source: Latch): Latch {.error.}
Source   Edit  
proc `=sink`(dest: var Latch; source: Latch) {.error.}
Source   Edit  
proc dec(x: var Latch) {....raises: [], tags: [], forbids: [].}
Tells the Latch that one worker has finished its task. Source   Edit  
proc initLatch(x: out Latch; count: Natural) {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc wait(x: var Latch) {....raises: [], tags: [], forbids: [].}
Waits until all workers have completed. Source   Edit