Skip to content
Snippets Groups Projects
Commit fed50c43 authored by Wan-Teh Chang's avatar Wan-Teh Chang Committed by Michael Niedermayer
Browse files

avutil: fix data race in av_get_cpu_flags()


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: default avatarWan-Teh Chang <wtc@google.com>
Signed-off-by: default avatarMichael Niedermayer <michael@niedermayer.cc>
parent 4cf3def8
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment