-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
ThreadSanitizer: false report about data race #52942
Comments
I have a related question. How can I tell ThreadSanitizer that some To demonstrate this, you can apply the following patch to dr-m/atomic_sync@aea7471: diff --git a/test/test_atomic_sync.cc b/test/test_atomic_sync.cc
index 6b53259..67c7ee6 100644
--- a/test/test_atomic_sync.cc
+++ b/test/test_atomic_sync.cc
@@ -8,7 +8,7 @@
#include "transactional_lock_guard.h"
#include "transactional_mutex_storage.h"
-static std::atomic<bool> critical;
+bool critical;
constexpr unsigned N_THREADS = 30;
constexpr unsigned N_ROUNDS = 100;
@@ -22,7 +22,7 @@ constexpr unsigned M_ROUNDS = 100;
# define atomic_spin_shared_mutex atomic_shared_mutex
# define atomic_spin_recursive_shared_mutex atomic_recursive_shared_mutex
#endif
-static atomic_spin_mutex<transactional_mutex_storage> m;
+static std::mutex m;
#if !defined WITH_ELISION || defined NDEBUG
# define transactional_assert(x) assert(x)
@@ -143,12 +143,10 @@ int main(int, char **)
fputs(ATOMIC_MUTEX_NAME(mutex), stderr);
#endif
- assert(!m.is_locked_or_waiting());
for (auto i = N_THREADS; i--; )
t[i]= std::thread(test_atomic_mutex);
for (auto i = N_THREADS; i--; )
t[i].join();
- assert(!m.is_locked_or_waiting());
fputs(", " ATOMIC_MUTEX_NAME(shared_mutex), stderr);
Compile and run as: mkdir build
cd build
cmake -DCMAKE_CXX_COMPILER=clang++-15 -DCMAKE_CXX_FLAGS='-stdlib=libc++ -fsanitize=thread' ..
cmake --build .
test/test_atomic_sync If you omit the second hunk, ThreadSanitizer will start to complain. I can’t use I assume that specially declaring a |
Sorry for the noise. I should have looked for |
The program as follows is valid:
The access to
state
variable is not a data race, because each thread before the modification executesatomic_thread_fence
to see the results of the other thread, and after the modification executes atomic store withmemory_order_release
. But the sanitizer erroneously reports data race. Demo: https://gcc.godbolt.org/z/9cY3aM3czRelated discussion: https://stackoverflow.com/q/70542993/7325599
The text was updated successfully, but these errors were encountered: