How to correctly capture variable to be used in proc which fed for a thread?
type MyProc = proc(): void
var threads: array[5, Thread[MyProc]]
proc execThread(prc: MyProc) {.thread.} =
echo "run ok"
prc()
for i in 0..threads.high:
closureScope:
threads[i].createThread execThread, proc () = echo i
threads.joinThread
When above code was ran, the captured i only the last, not each i. Thanks in advance.
