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):
let first = ... # computing first and last index of a chunk of data
let last = ...
createThread(threads[i], worker, (first, last))
joinThreads(threads)
Run
nim compiler output: Error: illegal capture 'res' because 'worker' has the
calling convention: <nimcall>
If I omit nimcall, the signature of the worker proc does not match the expected
2nd argument of createThread(). I do understand why these errors make sense in
general, but in this specific case it should be fine to capture res, since it's
of type Atomic, shouldn't it?
Is there anything I can do to convince the compiler to compile the code?
I know there are other ways to achieve what I want, but I'm currently only
interested in this specific case.