mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-04 04:02:41 +00:00
added system.runOnThreadCreationHandlers for initialization of thread local storage for the main thread
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user