the docs <https://nim-lang.org/docs/manual.html#threads-threadvar-pragma> state that: "(Every thread local variable needs to be replicated at thread creation.)"
So you somehow must do this: var foo {.threadvar.}: ref bool template fixFoo() = echo "define foo for: ", getThreadId() foo = new(bool) foo[] = false proc faa() {.thread.} = fixFoo() echo foo[] var th1: Thread[void] var th2: Thread[void] createThread(th1, faa) createThread(th2, faa) fixFoo() echo foo[] joinThreads(th1, th2) Run