• Wan-Teh Chang's avatar
    avutil: fix data race in av_get_cpu_flags() · fed50c43
    Wan-Teh Chang authored
    Make the one-time initialization in av_get_cpu_flags() thread-safe. The
    static variable |cpu_flags| in libavutil/cpu.c is read and written using
    normal load and store operations. These are considered as data races.
    The fix is to use atomic load and store operations.
    
    The fix can be verified by running the libavutil/tests/cpu_init.c test
    program under ThreadSanitizer:
        ./configure --toolchain=clang-tsan
        make libavutil/tests/cpu_init
        libavutil/tests/cpu_init
    
    There should be no warnings from ThreadSanitizer.
    
    Co-author: Dmitry Vyukov of Google, who suggested the data race fix.
    Signed-off-by: 's avatarWan-Teh Chang <wtc@google.com>
    Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
    fed50c43
cpu.h 4.92 KB