I see I managed to copy-paste the original snippet and not my edited version. 
This is what I meant to send:
    
    
    import std/locks
    
    var
      L: Lock
    
    var x = 0
    
    proc threadFunc(y: tuple[a, b: int]) {.thread.} =
      acquire(L) # lock stdout
      x.inc(y.a)
      echo y.b
      release(L)
    
    
    proc doIt() =
      initLock(L)
      var thr: array[0..4, Thread[tuple[a, b: int]]]
      for i in 0..high(thr):
        createThread(thr[i], threadFunc, (i, i*i))
      joinThreads(thr)
      
      deinitLock(L)
    
    doIt()
    echo x
    
    
    Run

Reply via email to