diff options
author | Araq <rumpf_a@web.de> | 2018-08-04 18:11:03 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2018-08-04 18:11:03 +0200 |
commit | e6738ba9d9f7b1221320a1fe49e6abba236b07a0 (patch) | |
tree | 131c7c32b2b5073b7921c5c4cb658f4abb24f02f | |
parent | e403ef25aceed929a3118e0dc2104c29e824dfcd (diff) | |
download | Nim-e6738ba9d9f7b1221320a1fe49e6abba236b07a0.tar.gz |
make 'echo' threadsafe on Windows; fixes #8511
-rw-r--r-- | lib/system/sysio.nim | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 2ece56916..7a10849dd 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -417,12 +417,18 @@ proc setStdIoUnbuffered() = discard c_setvbuf(stdin, nil, IONBF, 0) when declared(stdout): + when defined(windows) and compileOption("threads"): + var echoLock: SysLock + initSysLock echoLock + proc echoBinSafe(args: openArray[string]) {.compilerProc.} = # flockfile deadlocks some versions of Android 5.x.x when not defined(windows) and not defined(android) and not defined(nintendoswitch): proc flockfile(f: File) {.importc, noDecl.} proc funlockfile(f: File) {.importc, noDecl.} flockfile(stdout) + when defined(windows) and compileOption("threads"): + acquireSys echoLock for s in args: discard c_fwrite(s.cstring, s.len, 1, stdout) const linefeed = "\n" # can be 1 or more chars @@ -430,5 +436,7 @@ when declared(stdout): discard c_fflush(stdout) when not defined(windows) and not defined(android) and not defined(nintendoswitch): funlockfile(stdout) + when defined(windows) and compileOption("threads"): + releaseSys echoLock {.pop.} |