added system.runOnThreadCreationHandlers for initialization of thread local storage for the main thread
This commit is contained in:
parent
ea4397fbb0
commit
572fd067cf
1 changed files with 9 additions and 0 deletions
|
|
@ -327,6 +327,8 @@ proc onThreadCreation*(handler: proc () {.nimcall, gcsafe.}) =
|
||||||
## {.gcsafe.}:
|
## {.gcsafe.}:
|
||||||
## deepCopy(perThread, someGlobal)
|
## deepCopy(perThread, someGlobal)
|
||||||
##
|
##
|
||||||
|
## onThreadCreation(setPerThread)
|
||||||
|
##
|
||||||
## **Note**: The registration is currently not threadsafe! Better
|
## **Note**: The registration is currently not threadsafe! Better
|
||||||
## call ``onThreadCreation`` before any thread started its work!
|
## call ``onThreadCreation`` before any thread started its work!
|
||||||
threadCreationHandlers[countThreadCreationHandlers] = handler
|
threadCreationHandlers[countThreadCreationHandlers] = handler
|
||||||
|
|
@ -336,6 +338,13 @@ template beforeThreadRuns() =
|
||||||
for i in 0..countThreadCreationHandlers-1:
|
for i in 0..countThreadCreationHandlers-1:
|
||||||
threadCreationHandlers[i]()
|
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):
|
when not defined(boehmgc) and not hasSharedHeap and not defined(gogc) and not defined(gcstack):
|
||||||
proc deallocOsPages()
|
proc deallocOsPages()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue