I am working on a project that spawns threads that operate on a global memory 
array (seq[seq[uint64]]) and am trying to wrap my head around the locks module 
and passing variables to a threaded funtion. If I pass a single variable it 
works, but fails with N>1 variables.

Slightly modifying the example from the docs:

(this doesn't work)
    
    
    import std/locks
    
    var
      L: Lock
    
    var x = 0
    
    proc threadFunc(a, b: int) {.thread.} =
      acquire(L) # lock stdout
      x.inc(a)
      echo b
      release(L)
    
    
    proc doIt() =
      initLock(L)
      var thr: array[0..4, Thread[int]]
      for i in 0..high(thr):
        createThread(thr[i], threadFunc, (i, i*i))
      joinThreads(thr)
      
      deinitLock(L)
    
    doIt()
    echo x
    
    
    Run

I have tried variations of Thread[int] as well
    
    
    Thread[x, y: int]
    
    
    Run
    
    
    Thread[int, int]
    
    
    Run

So I am at an impasse as the function in my actual code takes a handful of 
varied arguments. Any pointers?

Reply via email to