I just noticed that the following code results in unexpected behavior.
Sometimes, the numbers are printed in random order to the console, sometimes
the program is stuck in the call to acquire with all cores close to 100% usage
and no output at all. Not sure if I'm doing something wrong, the only
difference between your code example and mine is that you acquire and release
the lock in the epilogue, not in the loop directly.
proc test() =
var lock: Lock
lock.initLock()
let lockAddr = lock.addr
parallelFor i in 0 ..< 10:
captures: {lockAddr}
lockAddr[].acquire() # stuck here
echo i
lockAddr[].release()
Run