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

But you should just use Weave or Malebolgia for threading, these also include 
examples how to process arrays in parallel etc.

Reply via email to