| Summary: | Thread sanitizer objects to SDL_AtomicGet | ||
|---|---|---|---|
| Product: | SDL | Reporter: | James Legg <jlegg> |
| Component: | atomic | Assignee: | Ryan C. Gordon <icculus> |
| Status: | VERIFIED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | minor | ||
| Priority: | P2 | CC: | icculus |
| Version: | HG 2.1 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Attachments: | patch | ||
This patch is now https://hg.libsdl.org/SDL/rev/623e8891e091, thanks! --ryan. |
Created attachment 2709 [details] patch SDL_AtomicGet and SDL_AtomicGetPtr attempt to perform an atomic load by repeatedly doing non-atomic loads and trying a compare and swap the loaded value with itself. The non-atomic loads are flagged as errors by thread sanitizer. For example: WARNING: ThreadSanitizer: data race (pid=8625) Read of size 4 at 0x7fb162d62240 by main thread: #0 SDL_AtomicGet_REAL SDL2-2.0.5/src/atomic/SDL_atomic.c:216 #1 SDL_AddTimer_REAL SDL2-2.0.5/src/timer/SDL_timer.c:285 #2 SDL_AddTimer SDL2-2.0.5/src/dynapi/SDL_dynapi_procs.h:520 Previous atomic write of size 4 at 0x7fb162d62240 by thread T1: #0 __tsan_atomic32_compare_exchange_weak <null> (libtsan.so.0+0x000000064163) #1 SDL_AtomicCAS_REAL SDL2-2.0.5/src/atomic/SDL_atomic.c:94 #2 SDL_AtomicGet_REAL SDL2-2.0.5/src/atomic/SDL_atomic.c:217 #3 SDL_TimerThread SDL2-2.0.5/src/timer/SDL_timer.c:141 #4 SDL_RunThread SDL2-2.0.5/src/thread/SDL_thread.c:283 #5 RunThread SDL2-2.0.5/src/thread/pthread/SDL_systhread.c:74 Location is global 'SDL_timer_data' of size 208 at 0x7fb162d62180 When GCC's built-in atomic operations are available, __atomic_load_n will perform an atomic load, and it will be correctly instrumented by thread sanitizer. The attached patch uses this.