Celtoys / Remotery

Single C file, Realtime CPU/GPU Profiler with Remote Web Viewer
Apache License 2.0
3.03k stars 255 forks source link

Thread Sanitizer data race issues. #240

Closed JCash closed 1 year ago

JCash commented 1 year ago

I wanted to create a small threaded test to run it through Clang's thread sanitizer, and it seems to produce a lot of output. I'm not sure how many are false positives, but I think it would be great if we could fix them somehow, since I hope more ppl will use the thread sanitizer (and other tools) on their projects in the future.

I have a branch draft here: https://github.com/Celtoys/Remotery/pull/239

I hope I have setup the test correctly. Currently only tested on macOS, but using pthreads, it should work on linux too.

Compile & run with:

clang -std=c89 -DRMT_ENABLED=1 -g -O0 -fsanitize=thread -Ilib sample/thread.c lib/Remotery.c -o build/test && ./build/test

Here's the output for the online readers:

Creating remotery instance
Spawning 4 threads
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Read of size 4 at 0x7b0800001174 by thread T3 (mutexes: write M22):
    #0 LoadAcquire Remotery.c:717 (test:x86_64+0x100002d29)
    #1 rmtMessageQueue_AllocMessage Remotery.c:4217 (test:x86_64+0x100007e06)
    #2 QueueAddToStringTable Remotery.c:5048 (test:x86_64+0x10001917f)
    #3 ThreadProfiler_Constructor Remotery.c:5145 (test:x86_64+0x100018e94)
    #4 ThreadProfilers_GetThreadProfiler Remotery.c:5433 (test:x86_64+0x100018b18)
    #5 ThreadProfilers_GetCurrentThreadProfiler Remotery.c:5459 (test:x86_64+0x10000514d)
    #6 _rmt_SetCurrentThreadName Remotery.c:7197 (test:x86_64+0x10000501c)
    #7 thread_start_proxy thread.c:33 (test:x86_64+0x1000020b2)

  Previous atomic write of size 4 at 0x7b0800001174 by thread T2:
    #0 __tsan_atomic32_compare_exchange_val <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x51b60)
    #1 AtomicCompareAndSwapU32 Remotery.c:633 (test:x86_64+0x10001a98f)
    #2 rmtMessageQueue_AllocMessage Remotery.c:4226 (test:x86_64+0x100007e98)
    #3 QueueSampleTree Remotery.c:5018 (test:x86_64+0x10000eda0)
    #4 ThreadProfiler_Pop Remotery.c:5240 (test:x86_64+0x100006187)
    #5 _rmt_EndCPUSample Remotery.c:7342 (test:x86_64+0x100005dc2)
    #6 Remotery_ThreadMain Remotery.c:6728 (test:x86_64+0x10000a7c5)
    #7 StartFunc Remotery.c:2158 (test:x86_64+0x100010e52)

  Location is heap block of size 24 at 0x7b0800001160 allocated by main thread:
    #0 malloc <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x532ec)
    #1 CRTMalloc Remotery.c:7002 (test:x86_64+0x100002f9f)
    #2 rmtMalloc Remotery.c:218 (test:x86_64+0x100003214)
    #3 Remotery_Constructor Remotery.c:6878 (test:x86_64+0x1000039a9)
    #4 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #5 main thread.c:133 (test:x86_64+0x1000021cf)

  Mutex M22 (0x7bb80000b030) created at:
    #0 pthread_mutex_init <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2cd05)
    #1 mtxInit Remotery.c:576 (test:x86_64+0x100008578)
    #2 ThreadProfilers_Constructor Remotery.c:5355 (test:x86_64+0x100009cf9)
    #3 Remotery_Constructor Remotery.c:6928 (test:x86_64+0x100004217)
    #4 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #5 main thread.c:133 (test:x86_64+0x1000021cf)

  Thread T3 (tid=17607725, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:717 in LoadAcquire
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Read of size 4 at 0x7b0800001170 by thread T3 (mutexes: write M22):
    #0 LoadAcquire Remotery.c:717 (test:x86_64+0x100002d29)
    #1 rmtMessageQueue_AllocMessage Remotery.c:4218 (test:x86_64+0x100007e16)
    #2 QueueAddToStringTable Remotery.c:5048 (test:x86_64+0x10001917f)
    #3 ThreadProfiler_Constructor Remotery.c:5145 (test:x86_64+0x100018e94)
    #4 ThreadProfilers_GetThreadProfiler Remotery.c:5433 (test:x86_64+0x100018b18)
    #5 ThreadProfilers_GetCurrentThreadProfiler Remotery.c:5459 (test:x86_64+0x10000514d)
    #6 _rmt_SetCurrentThreadName Remotery.c:7197 (test:x86_64+0x10000501c)
    #7 thread_start_proxy thread.c:33 (test:x86_64+0x1000020b2)

  Previous write of size 4 at 0x7b0800001170 by thread T2:
    #0 StoreRelease Remotery.c:732 (test:x86_64+0x10000f63d)
    #1 rmtMessageQueue_ConsumeNextMessage Remotery.c:4297 (test:x86_64+0x100015bab)
    #2 Remotery_ConsumeMessageQueue Remotery.c:6629 (test:x86_64+0x10001156e)
    #3 Remotery_ThreadMain Remotery.c:6725 (test:x86_64+0x10000a7bb)
    #4 StartFunc Remotery.c:2158 (test:x86_64+0x100010e52)

  Location is heap block of size 24 at 0x7b0800001160 allocated by main thread:
    #0 malloc <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x532ec)
    #1 CRTMalloc Remotery.c:7002 (test:x86_64+0x100002f9f)
    #2 rmtMalloc Remotery.c:218 (test:x86_64+0x100003214)
    #3 Remotery_Constructor Remotery.c:6878 (test:x86_64+0x1000039a9)
    #4 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #5 main thread.c:133 (test:x86_64+0x1000021cf)

  Mutex M22 (0x7bb80000b030) created at:
    #0 pthread_mutex_init <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2cd05)
    #1 mtxInit Remotery.c:576 (test:x86_64+0x100008578)
    #2 ThreadProfilers_Constructor Remotery.c:5355 (test:x86_64+0x100009cf9)
    #3 Remotery_Constructor Remotery.c:6928 (test:x86_64+0x100004217)
    #4 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #5 main thread.c:133 (test:x86_64+0x1000021cf)

  Thread T3 (tid=17607725, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:717 in LoadAcquire
==================
Entering thread!
Entering thread!
Entering thread!
Entering thread!
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Atomic write of size 8 at 0x7b0c00003058 by thread T2:
    #0 __tsan_atomic64_compare_exchange_val <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x51c70)
    #1 AtomicCompareAndSwapPointer Remotery.c:660 (test:x86_64+0x100010432)
    #2 ObjectAllocator_Push Remotery.c:2335 (test:x86_64+0x100010948)
    #3 ObjectAllocator_FreeRange Remotery.c:2423 (test:x86_64+0x10001071d)
    #4 FreeSamples Remotery.c:4938 (test:x86_64+0x10000ecdc)
    #5 Remotery_SendSampleTreeMessage Remotery.c:6415 (test:x86_64+0x1000155ca)
    #6 Remotery_ConsumeMessageQueue Remotery.c:6612 (test:x86_64+0x100011501)
    #7 Remotery_ThreadMain Remotery.c:6725 (test:x86_64+0x10000a7bb)
    #8 StartFunc Remotery.c:2158 (test:x86_64+0x100010e52)

  Previous read of size 8 at 0x7b0c00003058 by thread T3:
    #0 ObjectAllocator_Pop Remotery.c:2350 (test:x86_64+0x1000102f1)
    #1 ObjectAllocator_Alloc Remotery.c:2377 (test:x86_64+0x10000fc22)
    #2 SampleTree_Push Remotery.c:4849 (test:x86_64+0x10001a18a)
    #3 ThreadProfiler_Push Remotery.c:5185 (test:x86_64+0x100005b3f)
    #4 _rmt_BeginCPUSample Remotery.c:7312 (test:x86_64+0x100005871)
    #5 recursiveFunction thread.c:100 (test:x86_64+0x100002471)
    #6 Run thread.c:114 (test:x86_64+0x100002394)
    #7 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Location is heap block of size 48 at 0x7b0c00003030 allocated by thread T3:
    #0 malloc <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x532ec)
    #1 CRTMalloc Remotery.c:7002 (test:x86_64+0x100002f9f)
    #2 rmtMalloc Remotery.c:218 (test:x86_64+0x100003214)
    #3 SampleTree_Constructor Remotery.c:4769 (test:x86_64+0x10001935c)
    #4 ThreadProfiler_Constructor Remotery.c:5148 (test:x86_64+0x100018f61)
    #5 ThreadProfilers_GetThreadProfiler Remotery.c:5433 (test:x86_64+0x100018b18)
    #6 ThreadProfilers_GetCurrentThreadProfiler Remotery.c:5459 (test:x86_64+0x10000514d)
    #7 _rmt_SetCurrentThreadName Remotery.c:7197 (test:x86_64+0x10000501c)
    #8 thread_start_proxy thread.c:33 (test:x86_64+0x1000020b2)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

  Thread T3 (tid=17607725, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

SUMMARY: ThreadSanitizer: data race Remotery.c:660 in AtomicCompareAndSwapPointer
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Read of size 8 at 0x7b1c00003870 by thread T3:
    #0 ObjectAllocator_Pop Remotery.c:2355 (test:x86_64+0x100010322)
    #1 ObjectAllocator_Alloc Remotery.c:2377 (test:x86_64+0x10000fc22)
    #2 SampleTree_Push Remotery.c:4864 (test:x86_64+0x10001a31d)
    #3 ThreadProfiler_Push Remotery.c:5185 (test:x86_64+0x100005b3f)
    #4 _rmt_BeginCPUSample Remotery.c:7312 (test:x86_64+0x100005871)
    #5 Run thread.c:112 (test:x86_64+0x100002388)
    #6 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Previous write of size 8 at 0x7b1c00003870 by thread T2:
    #0 FlattenSamples Remotery.c:4911 (test:x86_64+0x100010559)
    #1 FreeSamples Remotery.c:4933 (test:x86_64+0x10000ec85)
    #2 Remotery_SendSampleTreeMessage Remotery.c:6415 (test:x86_64+0x1000155ca)
    #3 Remotery_ConsumeMessageQueue Remotery.c:6612 (test:x86_64+0x100011501)
    #4 Remotery_ThreadMain Remotery.c:6725 (test:x86_64+0x10000a7bb)
    #5 StartFunc Remotery.c:2158 (test:x86_64+0x100010e52)

  Location is heap block of size 112 at 0x7b1c00003870 allocated by thread T3:
    #0 malloc <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x532ec)
    #1 CRTMalloc Remotery.c:7002 (test:x86_64+0x100002f9f)
    #2 rmtMalloc Remotery.c:218 (test:x86_64+0x100003214)
    #3 ObjectAllocator_Alloc Remotery.c:2385 (test:x86_64+0x10000fc71)
    #4 SampleTree_Push Remotery.c:4864 (test:x86_64+0x10001a31d)
    #5 ThreadProfiler_Push Remotery.c:5185 (test:x86_64+0x100005b3f)
    #6 _rmt_BeginCPUSample Remotery.c:7312 (test:x86_64+0x100005871)
    #7 Run thread.c:112 (test:x86_64+0x100002388)
    #8 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Thread T3 (tid=17607725, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:2355 in ObjectAllocator_Pop
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Read of size 8 at 0x7b1c00010300 by thread T3:
    #0 ObjectAllocator_Pop Remotery.c:2355 (test:x86_64+0x100010322)
    #1 ObjectAllocator_Alloc Remotery.c:2377 (test:x86_64+0x10000fc22)
    #2 SampleTree_Push Remotery.c:4849 (test:x86_64+0x10001a18a)
    #3 ThreadProfiler_Push Remotery.c:5185 (test:x86_64+0x100005b3f)
    #4 _rmt_BeginCPUSample Remotery.c:7312 (test:x86_64+0x100005871)
    #5 recursiveFunction thread.c:100 (test:x86_64+0x100002471)
    #6 Run thread.c:114 (test:x86_64+0x100002394)
    #7 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Previous write of size 8 at 0x7b1c00010300 by thread T2:
    #0 FlattenSamples Remotery.c:4911 (test:x86_64+0x100010559)
    #1 FreeSamples Remotery.c:4933 (test:x86_64+0x10000ec85)
    #2 Remotery_SendSampleTreeMessage Remotery.c:6415 (test:x86_64+0x1000155ca)
    #3 Remotery_ConsumeMessageQueue Remotery.c:6612 (test:x86_64+0x100011501)
    #4 Remotery_ThreadMain Remotery.c:6725 (test:x86_64+0x10000a7bb)
    #5 StartFunc Remotery.c:2158 (test:x86_64+0x100010e52)

  Location is heap block of size 112 at 0x7b1c00010300 allocated by thread T3:
    #0 malloc <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x532ec)
    #1 CRTMalloc Remotery.c:7002 (test:x86_64+0x100002f9f)
    #2 rmtMalloc Remotery.c:218 (test:x86_64+0x100003214)
    #3 ObjectAllocator_Alloc Remotery.c:2385 (test:x86_64+0x10000fc71)
    #4 SampleTree_Push Remotery.c:4864 (test:x86_64+0x10001a31d)
    #5 ThreadProfiler_Push Remotery.c:5185 (test:x86_64+0x100005b3f)
    #6 _rmt_BeginCPUSample Remotery.c:7312 (test:x86_64+0x100005871)
    #7 Run thread.c:112 (test:x86_64+0x100002388)
    #8 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Thread T3 (tid=17607725, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:2355 in ObjectAllocator_Pop
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Read of size 8 at 0x7b1c0001d260 by thread T3:
    #0 ObjectAllocator_Pop Remotery.c:2355 (test:x86_64+0x100010322)
    #1 ObjectAllocator_Alloc Remotery.c:2377 (test:x86_64+0x10000fc22)
    #2 SampleTree_Push Remotery.c:4849 (test:x86_64+0x10001a18a)
    #3 ThreadProfiler_Push Remotery.c:5185 (test:x86_64+0x100005b3f)
    #4 _rmt_BeginCPUSample Remotery.c:7312 (test:x86_64+0x100005871)
    #5 aggregateFunction thread.c:95 (test:x86_64+0x1000024c4)
    #6 Run thread.c:113 (test:x86_64+0x10000238d)
    #7 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Previous write of size 8 at 0x7b1c0001d260 by thread T2:
    #0 FlattenSamples Remotery.c:4911 (test:x86_64+0x100010559)
    #1 FreeSamples Remotery.c:4933 (test:x86_64+0x10000ec85)
    #2 Remotery_SendSampleTreeMessage Remotery.c:6415 (test:x86_64+0x1000155ca)
    #3 Remotery_ConsumeMessageQueue Remotery.c:6612 (test:x86_64+0x100011501)
    #4 Remotery_ThreadMain Remotery.c:6725 (test:x86_64+0x10000a7bb)
    #5 StartFunc Remotery.c:2158 (test:x86_64+0x100010e52)

  Location is heap block of size 112 at 0x7b1c0001d260 allocated by thread T3:
    #0 malloc <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x532ec)
    #1 CRTMalloc Remotery.c:7002 (test:x86_64+0x100002f9f)
    #2 rmtMalloc Remotery.c:218 (test:x86_64+0x100003214)
    #3 ObjectAllocator_Alloc Remotery.c:2385 (test:x86_64+0x10000fc71)
    #4 SampleTree_Push Remotery.c:4864 (test:x86_64+0x10001a31d)
    #5 ThreadProfiler_Push Remotery.c:5185 (test:x86_64+0x100005b3f)
    #6 _rmt_BeginCPUSample Remotery.c:7312 (test:x86_64+0x100005871)
    #7 Run thread.c:112 (test:x86_64+0x100002388)
    #8 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Thread T3 (tid=17607725, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:2355 in ObjectAllocator_Pop
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Atomic write of size 8 at 0x7b0c00006058 by thread T2:
    #0 __tsan_atomic64_compare_exchange_val <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x51c70)
    #1 AtomicCompareAndSwapPointer Remotery.c:660 (test:x86_64+0x100010432)
    #2 ObjectAllocator_Push Remotery.c:2335 (test:x86_64+0x100010948)
    #3 ObjectAllocator_FreeRange Remotery.c:2423 (test:x86_64+0x10001071d)
    #4 FreeSamples Remotery.c:4938 (test:x86_64+0x10000ecdc)
    #5 Remotery_SendSampleTreeMessage Remotery.c:6415 (test:x86_64+0x1000155ca)
    #6 Remotery_ConsumeMessageQueue Remotery.c:6612 (test:x86_64+0x100011501)
    #7 Remotery_ThreadMain Remotery.c:6725 (test:x86_64+0x10000a7bb)
    #8 StartFunc Remotery.c:2158 (test:x86_64+0x100010e52)

  Previous read of size 8 at 0x7b0c00006058 by thread T5:
    #0 ObjectAllocator_Pop Remotery.c:2350 (test:x86_64+0x1000102f1)
    #1 ObjectAllocator_Alloc Remotery.c:2377 (test:x86_64+0x10000fc22)
    #2 SampleTree_Push Remotery.c:4864 (test:x86_64+0x10001a31d)
    #3 ThreadProfiler_Push Remotery.c:5185 (test:x86_64+0x100005b3f)
    #4 _rmt_BeginCPUSample Remotery.c:7312 (test:x86_64+0x100005871)
    #5 Run thread.c:112 (test:x86_64+0x100002388)
    #6 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Location is heap block of size 48 at 0x7b0c00006030 allocated by thread T5:
    #0 malloc <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x532ec)
    #1 CRTMalloc Remotery.c:7002 (test:x86_64+0x100002f9f)
    #2 rmtMalloc Remotery.c:218 (test:x86_64+0x100003214)
    #3 SampleTree_Constructor Remotery.c:4769 (test:x86_64+0x10001935c)
    #4 ThreadProfiler_Constructor Remotery.c:5148 (test:x86_64+0x100018f61)
    #5 ThreadProfilers_GetThreadProfiler Remotery.c:5433 (test:x86_64+0x100018b18)
    #6 ThreadProfilers_GetCurrentThreadProfiler Remotery.c:5459 (test:x86_64+0x10000514d)
    #7 _rmt_SetCurrentThreadName Remotery.c:7197 (test:x86_64+0x10000501c)
    #8 thread_start_proxy thread.c:33 (test:x86_64+0x1000020b2)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

  Thread T5 (tid=17607766, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

SUMMARY: ThreadSanitizer: data race Remotery.c:660 in AtomicCompareAndSwapPointer
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Write of size 8 at 0x0001092cbcb8 by thread T5:
    #0 QueueSampleTree Remotery.c:5030 (test:x86_64+0x10000ee49)
    #1 ThreadProfiler_Pop Remotery.c:5240 (test:x86_64+0x100006187)
    #2 _rmt_EndCPUSample Remotery.c:7342 (test:x86_64+0x100005dc2)
    #3 Run thread.c:115 (test:x86_64+0x100002399)
    #4 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Previous read of size 4 at 0x0001092cbcbc by thread T2:
    #0 rmtMessageQueue_ConsumeNextMessage Remotery.c:4292 (test:x86_64+0x100015b57)
    #1 Remotery_ConsumeMessageQueue Remotery.c:6629 (test:x86_64+0x10001156e)
    #2 Remotery_ThreadMain Remotery.c:6725 (test:x86_64+0x10000a7bb)
    #3 StartFunc Remotery.c:2158 (test:x86_64+0x100010e52)

  Thread T5 (tid=17607766, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:5030 in QueueSampleTree
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Write of size 8 at 0x0001092cec50 by thread T5:
    #0 rmtMessageQueue_AllocMessage Remotery.c:4230 (test:x86_64+0x100007ee1)
    #1 QueueSampleTree Remotery.c:5018 (test:x86_64+0x10000eda0)
    #2 ThreadProfiler_Pop Remotery.c:5240 (test:x86_64+0x100006187)
    #3 _rmt_EndCPUSample Remotery.c:7342 (test:x86_64+0x100005dc2)
    #4 Run thread.c:115 (test:x86_64+0x100002399)
    #5 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Previous read of size 8 at 0x0001092cec50 by thread T2:
    #0 bin_SampleTree Remotery.c:6295 (test:x86_64+0x10001656d)
    #1 Remotery_SendSampleTreeMessage Remotery.c:6406 (test:x86_64+0x10001553e)
    #2 Remotery_ConsumeMessageQueue Remotery.c:6612 (test:x86_64+0x100011501)
    #3 Remotery_ThreadMain Remotery.c:6725 (test:x86_64+0x10000a7bb)
    #4 StartFunc Remotery.c:2158 (test:x86_64+0x100010e52)

  Thread T5 (tid=17607766, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:4230 in rmtMessageQueue_AllocMessage
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Write of size 8 at 0x0001092cec90 by thread T4:
    #0 QueueSampleTree Remotery.c:5028 (test:x86_64+0x10000ede8)
    #1 ThreadProfiler_Pop Remotery.c:5240 (test:x86_64+0x100006187)
    #2 _rmt_EndCPUSample Remotery.c:7342 (test:x86_64+0x100005dc2)
    #3 Run thread.c:115 (test:x86_64+0x100002399)
    #4 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Previous read of size 4 at 0x0001092cec94 by thread T2:
    #0 bin_SampleTree Remotery.c:6324 (test:x86_64+0x10001681b)
    #1 Remotery_SendSampleTreeMessage Remotery.c:6406 (test:x86_64+0x10001553e)
    #2 Remotery_ConsumeMessageQueue Remotery.c:6612 (test:x86_64+0x100011501)
    #3 Remotery_ThreadMain Remotery.c:6725 (test:x86_64+0x10000a7bb)
    #4 StartFunc Remotery.c:2158 (test:x86_64+0x100010e52)

  Thread T4 (tid=17607726, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:5028 in QueueSampleTree
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Write of size 8 at 0x0001092cbd28 by thread T6:
    #0 QueueSampleTree Remotery.c:5030 (test:x86_64+0x10000ee49)
    #1 ThreadProfiler_Pop Remotery.c:5240 (test:x86_64+0x100006187)
    #2 _rmt_EndCPUSample Remotery.c:7342 (test:x86_64+0x100005dc2)
    #3 Run thread.c:115 (test:x86_64+0x100002399)
    #4 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Previous read of size 4 at 0x0001092cbd28 by thread T2:
    #0 LoadAcquire Remotery.c:717 (test:x86_64+0x100002d29)
    #1 rmtMessageQueue_PeekNextMessage Remotery.c:4269 (test:x86_64+0x100002cb7)
    #2 Remotery_ConsumeMessageQueue Remotery.c:6591 (test:x86_64+0x100011441)
    #3 Remotery_ThreadMain Remotery.c:6725 (test:x86_64+0x10000a7bb)
    #4 StartFunc Remotery.c:2158 (test:x86_64+0x100010e52)

  Thread T6 (tid=17607767, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:5030 in QueueSampleTree
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Write of size 4 at 0x0001092cbd7c by thread T3:
    #0 rmtMessageQueue_AllocMessage Remotery.c:4229 (test:x86_64+0x100007ebb)
    #1 QueueSampleTree Remotery.c:5018 (test:x86_64+0x10000eda0)
    #2 ThreadProfiler_Pop Remotery.c:5240 (test:x86_64+0x100006187)
    #3 _rmt_EndCPUSample Remotery.c:7342 (test:x86_64+0x100005dc2)
    #4 Run thread.c:115 (test:x86_64+0x100002399)
    #5 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Previous read of size 8 at 0x0001092cbd78 by thread T2:
    #0 Remotery_SendSampleTreeMessage Remotery.c:6415 (test:x86_64+0x1000155b9)
    #1 Remotery_ConsumeMessageQueue Remotery.c:6612 (test:x86_64+0x100011501)
    #2 Remotery_ThreadMain Remotery.c:6725 (test:x86_64+0x10000a7bb)
    #3 StartFunc Remotery.c:2158 (test:x86_64+0x100010e52)

  Thread T3 (tid=17607725, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:4229 in rmtMessageQueue_AllocMessage
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Write of size 8 at 0x0001092cbd80 by thread T3:
    #0 rmtMessageQueue_AllocMessage Remotery.c:4230 (test:x86_64+0x100007ee1)
    #1 QueueSampleTree Remotery.c:5018 (test:x86_64+0x10000eda0)
    #2 ThreadProfiler_Pop Remotery.c:5240 (test:x86_64+0x100006187)
    #3 _rmt_EndCPUSample Remotery.c:7342 (test:x86_64+0x100005dc2)
    #4 Run thread.c:115 (test:x86_64+0x100002399)
    #5 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Previous read of size 8 at 0x0001092cbd80 by thread T2:
    [failed to restore the stack]

  Thread T3 (tid=17607725, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:4230 in rmtMessageQueue_AllocMessage
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Write of size 8 at 0x0001092cbd88 by thread T3:
    #0 QueueSampleTree Remotery.c:5028 (test:x86_64+0x10000ede8)
    #1 ThreadProfiler_Pop Remotery.c:5240 (test:x86_64+0x100006187)
    #2 _rmt_EndCPUSample Remotery.c:7342 (test:x86_64+0x100005dc2)
    #3 Run thread.c:115 (test:x86_64+0x100002399)
    #4 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Previous read of size 4 at 0x0001092cbd8c by thread T2:
    [failed to restore the stack]

  Thread T3 (tid=17607725, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:5028 in QueueSampleTree
==================
==================
WARNING: ThreadSanitizer: data race (pid=72475)
  Write of size 8 at 0x0001092cbd98 by thread T3:
    #0 QueueSampleTree Remotery.c:5030 (test:x86_64+0x10000ee49)
    #1 ThreadProfiler_Pop Remotery.c:5240 (test:x86_64+0x100006187)
    #2 _rmt_EndCPUSample Remotery.c:7342 (test:x86_64+0x100005dc2)
    #3 Run thread.c:115 (test:x86_64+0x100002399)
    #4 thread_start_proxy thread.c:35 (test:x86_64+0x1000020e9)

  Previous read of size 4 at 0x0001092cbd98 by thread T2:
    [failed to restore the stack]

  Thread T3 (tid=17607725, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 thread_create thread.c:68 (test:x86_64+0x100001f9c)
    #2 main thread.c:145 (test:x86_64+0x10000226f)

  Thread T2 (tid=17607724, running) created by main thread at:
    #0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2bb6f)
    #1 rmtThread_Constructor Remotery.c:2199 (test:x86_64+0x10000a650)
    #2 Remotery_Constructor Remotery.c:6942 (test:x86_64+0x100004675)
    #3 _rmt_CreateGlobalInstance Remotery.c:7056 (test:x86_64+0x100003126)
    #4 main thread.c:133 (test:x86_64+0x1000021cf)

SUMMARY: ThreadSanitizer: data race Remotery.c:5030 in QueueSampleTree
dwilliamson commented 1 year ago

Can you move this post in here? https://github.com/Celtoys/Remotery/issues/195