We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
system.once isn't thread safe:
system.once
template once*(body: untyped): untyped = var alreadyExecuted {.global.} = false if not alreadyExecuted: alreadyExecuted = true body
when defined caseSub: const N = 10 var thr: array[N, Thread[int]] var count = 0 proc threadFunc(a: int) {.thread.} = once: count.inc doAssert count == 1 proc main = for i in 0..<N: createThread(thr[i], threadFunc, i) joinThreads(thr) main() else: import os, strformat proc main = const nim = getCurrentCompilerExe() const exe = "/tmp/z01b" const file = currentSourcePath # -d:danger let cmd = fmt"{nim} c -d:caseSub --threads -o:{exe} {file}" echo cmd doAssert execShellCmd(cmd) == 0 for i in 0..<10000: let ret = execShellCmd(exe) doAssert ret == 0, $i main()
fails after a few iterations: count == 1 [AssertionDefect]
count == 1
works
The text was updated successfully, but these errors were encountered:
probably needs import rlocks or locks?
EDIT: note from @xflywind : see https://github.com/golang/go/blob/master/src/sync/once.go
Sorry, something went wrong.
update: added a minimal repro, see top msg /cc @xflywind
Successfully merging a pull request may close this issue.
system.once
isn't thread safe:[EDIT] Example
Current output
fails after a few iterations:
count == 1
[AssertionDefect]Expected output
works
see also
The text was updated successfully, but these errors were encountered: