Hi. I thought I understood how the local heap in Nim works, but this simple
example shows that I don't (it throw an exception). What am I doing/thinking
wrong?
var myLocalThreadID = -1
proc initThreadID*(tid: int): void =
## Initialises the ThreadID. Can only be called once!
if myLocalThreadID != -1:
raise newException(Exception, "ThreadID already initialised: " &
$myLocalThreadID)
myLocalThreadID = tid
when isMainModule:
initThreadID(0)
# ...
proc receiver() {.thread.} =
initThreadID(1)
# ...
echo("receiver done!")
var thread: Thread[void]
createThread[void](thread, receiver)
joinThread(thread)
echo("main done!")
My assumption was that every thread, including the main thread, should get it's
_own copy_ of "myLocalThreadID" (because it's not _{.global.}_), safely
initialized to "-1" for each thread. This test proves me wrong. So either
"myLocalThreadID" is not local, or it is not initialised to "-1" (or something
else even stranger?).