You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In testthread, the main thread and a helper thread communicate via a global variable alive, but concurrent non-atomic accesses to variables are not thread-safe (undefined behaviour). ThreadSanitizer diagnoses this:
WARNING: ThreadSanitizer: data race (pid=1486312)
Read of size 4 at 0x55c924964494 by thread T1:
#0 ThreadFunc /home/smcv/src/SDL/test/testthread.c:65 (testthread+0x14df8) (BuildId: ff8455198b6ec3b4e9d2d60887c1c34f84865e83)
#1 SDL_RunThread /home/smcv/src/SDL/src/thread/SDL_thread.c:323 (libSDL3.so.0+0x850252) (BuildId: 2ad90d76e3ecc027c5bab3986c6c2f3310e6312f)
#2 RunThread /home/smcv/src/SDL/src/thread/pthread/SDL_systhread.c:69 (libSDL3.so.0+0xc89efd) (BuildId: 2ad90d76e3ecc027c5bab3986c6c2f3310e6312f)
Previous write of size 4 at 0x55c924964494 by main thread:
#0 main /home/smcv/src/SDL/test/testthread.c:147 (testthread+0x151f6) (BuildId: ff8455198b6ec3b4e9d2d60887c1c34f84865e83)
As if synchronized via sleep:
#0 nanosleep ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:397 (libtsan.so.2+0x54d2f) (BuildId: 10df5f7ccae7f4e0cda410a7307bbff5fb61b777)
#1 SDL_SYS_DelayNS /home/smcv/src/SDL/src/timer/unix/SDL_systimer.c:170 (libSDL3.so.0+0xc92065) (BuildId: 2ad90d76e3ecc027c5bab3986c6c2f3310e6312f)
#2 SDL_Delay_REAL /home/smcv/src/SDL/src/timer/SDL_timer.c:638 (libSDL3.so.0+0x853caf) (BuildId: 2ad90d76e3ecc027c5bab3986c6c2f3310e6312f)
#3 SDL_Delay /home/smcv/src/SDL/src/dynapi/SDL_dynapi_procs.h:165 (libSDL3.so.0+0x622d35) (BuildId: 2ad90d76e3ecc027c5bab3986c6c2f3310e6312f)
#4 ThreadFunc /home/smcv/src/SDL/test/testthread.c:75 (testthread+0x14dec) (BuildId: ff8455198b6ec3b4e9d2d60887c1c34f84865e83)
#5 SDL_RunThread /home/smcv/src/SDL/src/thread/SDL_thread.c:323 (libSDL3.so.0+0x850252) (BuildId: 2ad90d76e3ecc027c5bab3986c6c2f3310e6312f)
#6 RunThread /home/smcv/src/SDL/src/thread/pthread/SDL_systhread.c:69 (libSDL3.so.0+0xc89efd) (BuildId: 2ad90d76e3ecc027c5bab3986c6c2f3310e6312f)
Location is global 'alive' of size 4 at 0x55c924964494 (testthread+0x41494)
Thread T1 'One' (tid=1486314, running) created by main thread at:
#0 pthread_create ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:1022 (libtsan.so.2+0x568a6) (BuildId: 10df5f7ccae7f4e0cda410a7307bbff5fb61b777)
#1 SDL_SYS_CreateThread /home/smcv/src/SDL/src/thread/pthread/SDL_systhread.c:111 (libSDL3.so.0+0xc89fca) (BuildId: 2ad90d76e3ecc027c5bab3986c6c2f3310e6312f)
#2 SDL_CreateThreadWithPropertiesRuntime_REAL /home/smcv/src/SDL/src/thread/SDL_thread.c:383 (libSDL3.so.0+0x8505dc) (BuildId: 2ad90d76e3ecc027c5bab3986c6c2f3310e6312f)
#3 SDL_CreateThreadRuntime_REAL /home/smcv/src/SDL/src/thread/SDL_thread.c:403 (libSDL3.so.0+0x8507c7) (BuildId: 2ad90d76e3ecc027c5bab3986c6c2f3310e6312f)
#4 SDL_CreateThreadRuntime /home/smcv/src/SDL/src/dynapi/SDL_dynapi_procs.h:158 (libSDL3.so.0+0x622b43) (BuildId: 2ad90d76e3ecc027c5bab3986c6c2f3310e6312f)
#5 main /home/smcv/src/SDL/test/testthread.c:140 (testthread+0x151ad) (BuildId: ff8455198b6ec3b4e9d2d60887c1c34f84865e83)
SUMMARY: ThreadSanitizer: data race /home/smcv/src/SDL/test/testthread.c:65 in ThreadFunc
This should probably be a SDL_AtomicInt?
The text was updated successfully, but these errors were encountered:
slouken
added a commit
to slouken/SDL
that referenced
this issue
Sep 5, 2024
In
testthread
, the main thread and a helper thread communicate via a global variablealive
, but concurrent non-atomic accesses to variables are not thread-safe (undefined behaviour). ThreadSanitizer diagnoses this:This should probably be a
SDL_AtomicInt
?The text was updated successfully, but these errors were encountered: