mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-16 22:11:18 +00:00
Merge pull request #3786 from vegansk/disable_mthread_crash
Disable system.setupForeignThreadGc when it crashes
This commit is contained in:
@@ -78,19 +78,29 @@ iterator items(stack: ptr GcStack): ptr GcStack =
|
||||
yield s
|
||||
s = s.next
|
||||
|
||||
var
|
||||
localGcInitialized {.rtlThreadVar.}: bool
|
||||
# There will be problems with GC in foreign threads if `threads` option is off or TLS emulation is enabled
|
||||
const allowForeignThreadGc = compileOption("threads") and not compileOption("tlsEmulation")
|
||||
|
||||
proc setupForeignThreadGc*() =
|
||||
## call this if you registered a callback that will be run from a thread not
|
||||
## under your control. This has a cheap thread-local guard, so the GC for
|
||||
## this thread will only be initialized once per thread, no matter how often
|
||||
## it is called.
|
||||
if not localGcInitialized:
|
||||
localGcInitialized = true
|
||||
var stackTop {.volatile.}: pointer
|
||||
setStackBottom(addr(stackTop))
|
||||
initGC()
|
||||
when allowForeignThreadGc:
|
||||
var
|
||||
localGcInitialized {.rtlThreadVar.}: bool
|
||||
|
||||
proc setupForeignThreadGc*() =
|
||||
## Call this if you registered a callback that will be run from a thread not
|
||||
## under your control. This has a cheap thread-local guard, so the GC for
|
||||
## this thread will only be initialized once per thread, no matter how often
|
||||
## it is called.
|
||||
##
|
||||
## This function is availble only when ``--threads:on`` and ``--tlsEmulation:off``
|
||||
## switches are used
|
||||
if not localGcInitialized:
|
||||
localGcInitialized = true
|
||||
var stackTop {.volatile.}: pointer
|
||||
setStackBottom(addr(stackTop))
|
||||
initGC()
|
||||
else:
|
||||
template setupForeignThreadGc*(): stmt =
|
||||
{.error: "setupForeignThreadGc is availble only when ``--threads:on`` and ``--tlsEmulation:off`` are used".}
|
||||
|
||||
# ----------------- stack management --------------------------------------
|
||||
# inspired from Smart Eiffel
|
||||
|
||||
Reference in New Issue
Block a user