diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-01-28 10:14:48 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2016-01-28 10:14:48 +0100 |
commit | 611c74f2d438c008836551aca641f2058a26ae8e (patch) | |
tree | 9fc2b4b3d16a1cae56fb8b677dd3f58ef9ce2047 | |
parent | 4c2894ca26c24c511186014a6bd173b564053912 (diff) | |
parent | 4f8244c7173638634076295a8bcb0bd3504859d1 (diff) | |
download | Nim-611c74f2d438c008836551aca641f2058a26ae8e.tar.gz |
Merge pull request #3786 from vegansk/disable_mthread_crash
Disable system.setupForeignThreadGc when it crashes
-rw-r--r-- | lib/system/gc_common.nim | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/lib/system/gc_common.nim b/lib/system/gc_common.nim index fdedcaf18..013dc55f8 100644 --- a/lib/system/gc_common.nim +++ b/lib/system/gc_common.nim @@ -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 |