As QMaster points out Nim `spawn` will deeply copy the element. That being said 
it's not a great idea to have a table with strings in a shared structure. Those 
strings will be owned by whichever thread created them, and the thread might 
free that memory if it finds it is no longer in use (in that thread).

That being said if you compile with `--gc:arc` your example works as you 
expect. With the new ARC GC we are allowed to share memory between threads like 
this and as such those `spawn` calls doesn't deep copy the memory. There's also 
no issue of sharing the string keys under ARC.

However as @boia01 pointed out you're not guaranteed to always get 1000, and I 
don't think you are guaranteed that in the Go version either. Since your 
threads to so little work it is probably most likely to happen that way, but 
it's not guaranteed.

Reply via email to