We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3620 - Thread sanitizer objects to SDL_AtomicGet
Summary: Thread sanitizer objects to SDL_AtomicGet
Status: VERIFIED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: atomic (show other bugs)
Version: HG 2.1
Hardware: x86_64 Linux
: P2 minor
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-29 15:15 UTC by James Legg
Modified: 2017-03-29 16:04 UTC (History)
1 user (show)

See Also:


Attachments
patch (1.09 KB, text/plain)
2017-03-29 15:15 UTC, James Legg
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Legg 2017-03-29 15:15:20 UTC
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.
Comment 1 Ryan C. Gordon 2017-03-29 15:57:13 UTC
This patch is now https://hg.libsdl.org/SDL/rev/623e8891e091, thanks!

--ryan.