By making it as argument for the proc in object seems captured it correctly.
type
MyObpr = object
theproc: proc(x: int): void
thearg: int
var threads: array[5, Thread[MyObpr]]
proc execThread(o: MyObpr) {.thread.} =
echo "run ok"
o.theproc o.thearg
for i in 0..threads.high:
closureScope:
threads[i].createThread execThread, MyObpr(thearg: i,
theproc: proc(x: int) = echo x)
threads.joinThreads
Could anyone explain the different between capturing within body of proc and as argument?
