summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xlib/core/threads.nim4
-rwxr-xr-xlib/system/excpt.nim5
2 files changed, 5 insertions, 4 deletions
diff --git a/lib/core/threads.nim b/lib/core/threads.nim
index 4e13d66de..fab8251f6 100755
--- a/lib/core/threads.nim
+++ b/lib/core/threads.nim
@@ -160,9 +160,9 @@ else:
 type
   TThread* {.pure, final.}[TParam] = object ## Nimrod thread.
     sys: TSysThread
+    globals: pointer # this allows the GC to track thread local storage!
     c: TThreadProcClosure[TParam]
 
-
 when nodeadlocks:
   var 
     lockList {.threadvar.}: ptr TLock
@@ -283,7 +283,7 @@ proc createThread*[TParam](t: var TThread[TParam],
   ## proc `tp`. `param` is passed to `tp`.
   t.c.data = param
   t.c.fn = tp
-  CreateThreadLocalStorage()
+  t.globals = CreateThreadLocalStorage()
   when hostOS == "windows":
     var dummyThreadId: int32
     t.sys = CreateThread(nil, 0'i32, threadProcWrapper[TParam], 
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index 9bdc69569..e2d3bea08 100755
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -106,9 +106,10 @@ when hasThreadSupport:
     PGlobals = ptr TGlobals
 
   var globalsSlot = ThreadVarAlloc()
-  proc CreateThreadLocalStorage*() {.inl.} =
+  proc CreateThreadLocalStorage*(): pointer {.inl.} =
     isMultiThreaded = true
-    ThreadVarSetValue(globalsSlot, alloc0(sizeof(TGlobals)))
+    result = alloc0(sizeof(TGlobals))
+    ThreadVarSetValue(globalsSlot, result)
     
   proc GetGlobals(): PGlobals {.compilerRtl, inl.} =
     result = cast[PGlobals](ThreadVarGetValue(globalsSlot))