diff options
-rw-r--r-- | lib/system/threads.nim | 9 |
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() |