I am created a shared table but then each value comes from a ref object located on a different thread.
So in the end globalTable will point to 10 ref objects all from different heaps. Will this cause memory corruptions?
import os, collections/sharedtables
type Foo = ref object
a, b, c: int
var
globalTable: SharedTable[int, Foo]
thr: array[0 .. 10, Thread[int]]
proc threadFunc(index: int) {.thread.} =
for i in 0 ..< 10:
echo index, " ", i
globalTable[index] = Foo(a: index, b:i, c:123)
sleep(5)
globalTable.init()
for i in 0 ..< thr.len:
createThread(thr[i], threadFunc, i)
sleep(10000)