Araq / malebolgia

Malebolgia creates new spawns. Structured concurrency. Thread pools and related APIs.
MIT License
104 stars 10 forks source link

ThreadSanitizer Error when running tests #4

Closed planetis-m closed 1 year ago

planetis-m commented 1 year ago

This error pops up when running the tests with threadsanitizer. command: nim c --cc:clang -d:useMalloc -t:"-fsanitize=thread" -l:"-fsanitize=thread" -d:nosignalhandler -d:release -g test1

LLVMSymbolizer: error reading file: No such file or directory
==================
WARNING: ThreadSanitizer: data race (pid=13808)
  Write of size 8 at 0x7fff7d6bf1d8 by main thread:
    #0 pthread_cond_destroy <null> (test1+0x8dd45) (BuildId: f600fc0c8e8708fdf1ca7711971442600b2f1f8e)
    #1 deinitCond__coreZlocks_u20 /home/antonisg/build/Nim/lib/core/locks.nim:65:2 (test1+0xefbc2) (BuildId: f600fc0c8e8708fdf1ca7711971442600b2f1f8e)
    #2 eqdestroy___OOZsrcZmalebolgia_u18 /home/antonisg/code/malebolgia/src/malebolgia.nim:14:2 (test1+0xefbc2)
    #3 main__test49_u37 /home/antonisg/code/malebolgia/src/malebolgia.nim:13:3 (test1+0xefbc2)
    #4 NimMainModule /home/antonisg/code/malebolgia/tests/test1.nim:18:2 (test1+0xefe37) (BuildId: f600fc0c8e8708fdf1ca7711971442600b2f1f8e)
    #5 NimMainInner /home/antonisg/code/malebolgia/src/malebolgia.nim:36:2 (test1+0xefe37)
    #6 NimMain /home/antonisg/code/malebolgia/src/malebolgia.nim:47:2 (test1+0xefe37)
    #7 main /home/antonisg/code/malebolgia/src/malebolgia.nim:55:3 (test1+0xefe37)

  Previous read of size 8 at 0x7fff7d6bf1d8 by thread T241:
    #0 pthread_cond_signal <null> (test1+0x8d805) (BuildId: f600fc0c8e8708fdf1ca7711971442600b2f1f8e)
    #1 signal__coreZlocks_u25 /home/antonisg/build/Nim/lib/core/locks.nim:73:2 (test1+0xee912) (BuildId: f600fc0c8e8708fdf1ca7711971442600b2f1f8e)
    #2 taskCompleted__OOZsrcZmalebolgia_u92 /home/antonisg/code/malebolgia/src/malebolgia.nim:39:2 (test1+0xee912)
    #3 worker__OOZsrcZmalebolgia_u177 /home/antonisg/code/malebolgia/src/malebolgia.nim:113:4 (test1+0xee912)
    #4 threadProcWrapDispatch__stdZtypedthreads_u105 /home/antonisg/build/Nim/lib/system/threadimpl.nim:71:2 (test1+0xedca3) (BuildId: f600fc0c8e8708fdf1ca7711971442600b2f1f8e)
    #5 threadProcWrapStackFrame__stdZtypedthreads_u95 /home/antonisg/build/Nim/lib/system/threadimpl.nim:100:2 (test1+0xedca3)
    #6 threadProcWrapper__stdZtypedthreads_u81 /home/antonisg/build/Nim/lib/system/threadimpl.nim:106:2 (test1+0xe8983) (BuildId: f600fc0c8e8708fdf1ca7711971442600b2f1f8e)

  Location is stack of main thread.

  Location is global '??' at 0x7fff7d6a0000 ([stack]+0x1f1d8)

  Thread T241 (tid=14050, running) created by main thread at:
    #0 pthread_create <null> (test1+0x67206) (BuildId: f600fc0c8e8708fdf1ca7711971442600b2f1f8e)
    #1 createThread__stdZtypedthreads_u60 /home/antonisg/build/Nim/lib/std/typedthreads.nim:246:106 (test1+0xe8acb) (BuildId: f600fc0c8e8708fdf1ca7711971442600b2f1f8e)
    #2 setup__OOZsrcZmalebolgia_u226 /home/antonisg/code/malebolgia/src/malebolgia.nim:119:94 (test1+0xef54a) (BuildId: f600fc0c8e8708fdf1ca7711971442600b2f1f8e)
    #3 atmdotdotatssrcatsmalebolgiadotnim_Init000 /home/antonisg/code/malebolgia/src/malebolgia.nim:140:2 (test1+0xef54a)
    #4 PreMainInner /home/antonisg/code/malebolgia/src/malebolgia.nim:19:2 (test1+0xefe32) (BuildId: f600fc0c8e8708fdf1ca7711971442600b2f1f8e)
    #5 PreMain /home/antonisg/code/malebolgia/src/malebolgia.nim:31:2 (test1+0xefe32)
    #6 NimMain /home/antonisg/code/malebolgia/src/malebolgia.nim:46:2 (test1+0xefe32)
    #7 main /home/antonisg/code/malebolgia/src/malebolgia.nim:55:3 (test1+0xefe32)

SUMMARY: ThreadSanitizer: data race (/home/antonisg/code/malebolgia/tests/test1+0x8dd45) (BuildId: f600fc0c8e8708fdf1ca7711971442600b2f1f8e) in pthread_cond_destroy
==================
ThreadSanitizer: reported 1 warnings
Araq commented 1 year ago

Makes no sense to me. When the destructor runs we know that m.runningTasks == 0 which means a thread cannot read/write to the condition variable anymore.

Araq commented 1 year ago

The sanitizer doesn't understand POSIX signals.

Araq commented 1 year ago

I ended up listening to you anyway because the M1 wasn't happy with the signals outside of the locks and it's faster this way for common pthread implementations because they employ a specific optimization for this case.