-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[tsan] False warning when using std::condition_variable #1259
Comments
I ran into this issue in spdlog while upgrading a toolchain. I am also able to reproduce this issue on Arch Linux. Compiling with -stdlib=libc++ makes the issue disappear. After a closer look, it seems there were some changes in libstdc++ which cause wait_until to be compiled with pthread_cond_clockwait (new in glibc 2.30).
The code is gated behind the macro _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT. On Arch Linux this is defined in /usr/include/c++/10.1.0/x86_64-pc-linux-gnu/bits/c++config.h.
If the above line is commented out, the double lock error disappears. I would assume this means tsan needs to add support for pthread_cond_clockwait. |
I ran into a similar issue, but with libstdc++ it works fine whereas for libc++ those false positives show up. _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT is not defined in /usr/include/x86_64-pc-linux-gnu/c++/9/bits/c++config.h. But a similar symbol _LIBCPP_HAS_COND_CLOCKWAIT is defined in /usr/lib/llvm-10/include/c++/v1/__config. Removing _LIBCPP_HAS_COND_CLOCKWAIT makes the false positives disappear. Tested system: |
Same with debian looking what can be done in tsan about pthread_cond_clockwait |
Adding an interceptor in compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp similar to the one for |
Great, thank you for the fix |
Disable the test on old systems. pthread_cond_clockwait is supported by glibc-2.30. It also supported by Android api 30 even though we do not run tsan on Android. Fixes google/sanitizers#1259 Reviewed By: dvyukov
Fixes google/sanitizers#1259 Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D91684
Disable the test on old systems. pthread_cond_clockwait is supported by glibc-2.30. It also supported by Android api 30 even though we do not run tsan on Android. Fixes google/sanitizers#1259 Reviewed By: dvyukov
Great! Which clang version will this land in? |
The iothread pool has a feature where, if the thread is emptied, some threads will choose to wait around in case new work appears, up to a certain amount of time (500 msec). This prevents thrashing where new threads are rapidly created and destroyed as the user types. This is implemented via `std::condition_variable::wait_for`. However this function is not properly instrumented under Thread Sanitizer (see google/sanitizers#1259) so TSan reports false positives. Just disable this feature under TSan.
The iothread pool has a feature where, if the thread is emptied, some threads will choose to wait around in case new work appears, up to a certain amount of time (500 msec). This prevents thrashing where new threads are rapidly created and destroyed as the user types. This is implemented via `std::condition_variable::wait_for`. However this function is not properly instrumented under Thread Sanitizer (see google/sanitizers#1259) so TSan reports false positives. Just disable this feature under TSan.
Fixes google/sanitizers#1259 Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D91684
Disable the test on old systems. pthread_cond_clockwait is supported by glibc-2.30. It also supported by Android api 30 even though we do not run tsan on Android. Fixes google/sanitizers#1259 Reviewed By: dvyukov
Clang's ThreadSanitizer in version 10 and 11 emits a false positive when using condition variables ("WARNING: ThreadSanitizer: double lock of a mutex"). This was fixed in version 12 (google/sanitizers#1259).
I have false positives in GCC 10 and clang 10 and 11. The false positives disappear for me in GCC 8, 9 and clang 12. |
Fixes google/sanitizers#1259 Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D91684
Disable the test on old systems. pthread_cond_clockwait is supported by glibc-2.30. It also supported by Android api 30 even though we do not run tsan on Android. Fixes google/sanitizers#1259 Reviewed By: dvyukov
See llvm/llvm-project#62623 which points out that interceptors are still missing for |
When compiling the following code with clang, utilizing thread sanitizer, I get false warnings.
Generated warnings when running the program:
I am building the code with the following command:
The version of my compiler is:
tsan library info:
I also posted a question regarding this behavior on stackoverflow: https://stackoverflow.com/questions/62188442/clang-thread-sanitizer-reports-issues-when-using-conditon-variables
Apparently, the warnings are only reported when using clang-10.0.0, they are not reported when using older compiler versions. I could reproduce this behavior on two separate machines running Arch Linux with the latest shipped clang version.
The text was updated successfully, but these errors were encountered: