I played a bit with threads and spawn and I had issues with the gc safety of the procs I wanted to spawn/run in threads.
What is exactly gc safety ? The manual explains that 'a proc is gc safe when it doesn't access any global variable that contains GC'ed memory'. What is the reason for that ?
Thanks.
What is a GCed reference in global variables ?
For example I had the issue with a constant array of strings.
let array = ["foo", "bar"]
Why can't I use this array ? How can accessing these affect the GC behavior of threads ?
To expand on what Araq said: strings are allocated on the heap and garbage collected (arrays are not, but the string references inside still need to point somewhere).
Using const allows you to circumvent this, because consts are allocated in static memory.
In general, ref types, strings, and seqs are heap references that you can't easily share between multiple threads.
So the garbage collection happens per thread and sharing memory is not easy.
I think I get it but what is the nim idiom to share global resources between threads ?