For some reason, it works as intended if I pass a ptr Lock to the function
instead of initializing it inside the function:
proc test(lock: ptr Lock) =
parallelFor i in 0 ..< 10:
captures:{lock}
lock[].acquire()
echo i
lock[].release()
wh
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
Thanks for pointing that out, it's a really helpful example for me. I just
started getting into weave and laser recently and I'm pretty sure I would
sooner or later stumble over a similar problem. I'm planning on implementing
some algorithms using weave to compare performance of various programm
Thanks for your answers, I ended up doing what both of you suggested. I was
hoping to find a way to not use raw pointers explicitly but I guess it makes no
difference in the end.
proc main() =
var threads: array[0..4, Thread[tuple[a, b: int]]]
var res: Atomic[int]
proc worker(interval: tuple[a, b: int]) {.gcsafe, nimcall, thread.} =
# loop over interval and compute some value
res += value
for i in 0..high(threads):