[peter /tmp ] 11852 $ cat test_globals.nim var commChan: Channel[string] sender: Thread[void] receiver: Thread[void] proc setupSender() = echo "Type in a message to send to the Backend!" proc sendMsg() = when true: let terminalInput = "Hello world" echo "Sending message from Frontend from thread ", getThreadId(), ": ", terminalInput commChan.send(terminalInput) createThread(sender, sendMsg) proc setupReceiver() = proc recvMsg() = when true: let msg: string = commChan.recv() echo "Received message at Backend on Thread: ", getThreadId(), " :", msg createThread(receiver, recvMsg) proc main() = commChan.open() setupSender() setupReceiver() joinThreads(sender, receiver) main() [peter /tmp ] 11853 $ nim c --debugger:native -d:useMalloc test_globals Hint: used config file '/home/peter/.choosenim/toolchains/nim-2.0.0/config/nim.cfg' [Conf] Hint: used config file '/home/peter/.choosenim/toolchains/nim-2.0.0/config/config.nims' [Conf] ..................................................................... Hint: [Link] Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code) 26256 lines; 0.182s; 30.324MiB peakmem; proj: /tmp/test_globals; out: /tmp/test_globals [SuccessX] [peter /tmp ] 11854 $ valgrind --tool=helgrind ./test_globals ==61102== Helgrind, a thread error detector ==61102== Copyright (C) 2007-2017, and GNU GPL'd, by OpenWorks LLP et al. ==61102== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info ==61102== Command: ./test_globals ==61102== Type in a message to send to the Backend! Sending message from Frontend from thread 61108: Hello world Received message at Backend on Thread: 61109 :Hello world ==61102== ---Thread-Announcement------------------------------------------ ==61102== ==61102== Thread #1 is the program's root thread ==61102== ==61102== ---Thread-Announcement------------------------------------------ ==61102== ==61102== Thread #2 was created ==61102== at 0x49AE643: clone (clone.S:76) ==61102== by 0x49AE790: __clone_internal_fallback (clone-internal.c:71) ==61102== by 0x49AE790: __clone_internal (clone-internal.c:117) ==61102== by 0x492A5EF: create_thread (pthread_create.c:297) ==61102== by 0x492B0FF: pthread_create@@GLIBC_2.34 (pthread_create.c:833) ==61102== by 0x484D615: pthread_create_WRK (hg_intercepts.c:445) ==61102== by 0x10B72F: createThread__stdZtypedthreads_u60 (typedthreads.nim:246) ==61102== by 0x10B826: createThread__stdZtypedthreads_u51 (typedthreads.nim:262) ==61102== by 0x111AFE: setupSender__test95globals_u7 (test_globals.nim:15) ==61102== by 0x111C22: main__test95globals_u85 (test_globals.nim:27) ==61102== by 0x111D2C: NimMainModule (test_globals.nim:31) ==61102== by 0x111D95: NimMainInner (test_globals.nim:54) ==61102== by 0x111DA8: NimMain (test_globals.nim:65) ==61102== ==61102== ---------------------------------------------------------------- ==61102== ==61102== Possible data race during read of size 8 at 0x117480 by thread #1 ==61102== Locks held: none ==61102== at 0x111C54: main__test95globals_u85 (test_globals.nim:29) ==61102== by 0x111D2C: NimMainModule (test_globals.nim:31) ==61102== by 0x111D95: NimMainInner (test_globals.nim:54) ==61102== by 0x111DA8: NimMain (test_globals.nim:65) ==61102== by 0x111DCA: main (test_globals.nim:73) ==61102== ==61102== This conflicts with a previous write of size 8 by thread #2 ==61102== Locks held: none ==61102== at 0x10B676: threadProcWrapper__stdZtypedthreads_u81 (threadimpl.nim:109) ==61102== by 0x484D81A: mythread_wrapper (hg_intercepts.c:406) ==61102== by 0x492A9EA: start_thread (pthread_create.c:444) ==61102== by 0x49AE653: clone (clone.S:100) ==61102== Address 0x117480 is 0 bytes inside data symbol "sender__test95globals_u4" ==61102== ==61102== ---------------------------------------------------------------- ==61102== ==61102== Possible data race during read of size 8 at 0x117490 by thread #1 ==61102== Locks held: none ==61102== at 0x111C61: main__test95globals_u85 (test_globals.nim:29) ==61102== by 0x111D2C: NimMainModule (test_globals.nim:31) ==61102== by 0x111D95: NimMainInner (test_globals.nim:54) ==61102== by 0x111DA8: NimMain (test_globals.nim:65) ==61102== by 0x111DCA: main (test_globals.nim:73) ==61102== ==61102== This conflicts with a previous write of size 8 by thread #2 ==61102== Locks held: none ==61102== at 0x10B67D: threadProcWrapper__stdZtypedthreads_u81 (threadimpl.nim:110) ==61102== by 0x484D81A: mythread_wrapper (hg_intercepts.c:406) ==61102== by 0x492A9EA: start_thread (pthread_create.c:444) ==61102== by 0x49AE653: clone (clone.S:100) ==61102== Address 0x117490 is 16 bytes inside data symbol "sender__test95globals_u4" ==61102== ==61102== ---Thread-Announcement------------------------------------------ ==61102== ==61102== Thread #3 was created ==61102== at 0x49AE643: clone (clone.S:76) ==61102== by 0x49AE790: __clone_internal_fallback (clone-internal.c:71) ==61102== by 0x49AE790: __clone_internal (clone-internal.c:117) ==61102== by 0x492A5EF: create_thread (pthread_create.c:297) ==61102== by 0x492B0FF: pthread_create@@GLIBC_2.34 (pthread_create.c:833) ==61102== by 0x484D615: pthread_create_WRK (hg_intercepts.c:445) ==61102== by 0x10B72F: createThread__stdZtypedthreads_u60 (typedthreads.nim:246) ==61102== by 0x10B826: createThread__stdZtypedthreads_u51 (typedthreads.nim:262) ==61102== by 0x111B8A: setupReceiver__test95globals_u67 (test_globals.nim:23) ==61102== by 0x111C3D: main__test95globals_u85 (test_globals.nim:28) ==61102== by 0x111D2C: NimMainModule (test_globals.nim:31) ==61102== by 0x111D95: NimMainInner (test_globals.nim:54) ==61102== by 0x111DA8: NimMain (test_globals.nim:65) ==61102== ==61102== ---------------------------------------------------------------- ==61102== ==61102== Possible data race during read of size 8 at 0x117460 by thread #1 ==61102== Locks held: none ==61102== at 0x111C6D: main__test95globals_u85 (test_globals.nim:29) ==61102== by 0x111D2C: NimMainModule (test_globals.nim:31) ==61102== by 0x111D95: NimMainInner (test_globals.nim:54) ==61102== by 0x111DA8: NimMain (test_globals.nim:65) ==61102== by 0x111DCA: main (test_globals.nim:73) ==61102== ==61102== This conflicts with a previous write of size 8 by thread #3 ==61102== Locks held: none ==61102== at 0x10B676: threadProcWrapper__stdZtypedthreads_u81 (threadimpl.nim:109) ==61102== by 0x484D81A: mythread_wrapper (hg_intercepts.c:406) ==61102== by 0x492A9EA: start_thread (pthread_create.c:444) ==61102== by 0x49AE653: clone (clone.S:100) ==61102== Address 0x117460 is 0 bytes inside data symbol "receiver__test95globals_u6" ==61102== ==61102== ---------------------------------------------------------------- ==61102== ==61102== Possible data race during read of size 8 at 0x117470 by thread #1 ==61102== Locks held: none ==61102== at 0x111C7A: main__test95globals_u85 (test_globals.nim:29) ==61102== by 0x111D2C: NimMainModule (test_globals.nim:31) ==61102== by 0x111D95: NimMainInner (test_globals.nim:54) ==61102== by 0x111DA8: NimMain (test_globals.nim:65) ==61102== by 0x111DCA: main (test_globals.nim:73) ==61102== ==61102== This conflicts with a previous write of size 8 by thread #3 ==61102== Locks held: none ==61102== at 0x10B67D: threadProcWrapper__stdZtypedthreads_u81 (threadimpl.nim:110) ==61102== by 0x484D81A: mythread_wrapper (hg_intercepts.c:406) ==61102== by 0x492A9EA: start_thread (pthread_create.c:444) ==61102== by 0x49AE653: clone (clone.S:100) ==61102== Address 0x117470 is 16 bytes inside data symbol "receiver__test95globals_u6" ==61102== ==61102== ==61102== Use --history-level=approx or =none to gain increased speed, at ==61102== the cost of reduced accuracy of conflicting-access information ==61102== For lists of detected and suppressed errors, rerun with: -s ==61102== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 7 from 7)