summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2017-01-20 20:31:59 +0100
committerAraq <rumpf_a@web.de>2017-01-20 20:32:41 +0100
commit572fd067cff6dfab8f79bc243cd21f1fc4b0b7f3 (patch)
treebfbcbc0179f1cb7d3b41f28b3fc891e98a4a3fe4 /lib
parentea4397fbb084a8d316ae71eaf4f66941e4e8a97c (diff)
downloadNim-572fd067cff6dfab8f79bc243cd21f1fc4b0b7f3.tar.gz
added system.runOnThreadCreationHandlers for initialization of thread local storage for the main thread
Diffstat (limited to 'lib')
-rw-r--r--lib/system/threads.nim9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/system/threads.nim b/lib/system/threads.nim
index dea6fff1c..3291d8c73 100644
--- a/lib/system/threads.nim
+++ b/lib/system/threads.nim
@@ -327,6 +327,8 @@ proc onThreadCreation*(handler: proc () {.nimcall, gcsafe.}) =
   ##    {.gcsafe.}:
   ##      deepCopy(perThread, someGlobal)
   ##
+  ##  onThreadCreation(setPerThread)
+  ##
   ## **Note**: The registration is currently not threadsafe! Better
   ## call ``onThreadCreation`` before any thread started its work!
   threadCreationHandlers[countThreadCreationHandlers] = handler
@@ -336,6 +338,13 @@ template beforeThreadRuns() =
   for i in 0..countThreadCreationHandlers-1:
     threadCreationHandlers[i]()
 
+proc runOnThreadCreationHandlers*() =
+  ## This runs every registered ``onThreadCreation`` handler and is usually
+  ## used to initialize thread local storage for the main thread. Since the
+  ## main thread is **not** created via ``createThread`` it doesn't run the
+  ## handlers automatically.
+  beforeThreadRuns()
+
 when not defined(boehmgc) and not hasSharedHeap and not defined(gogc) and not defined(gcstack):
   proc deallocOsPages()