thread-sanitizer

Thread sanitizer reports data race when using std::packaged_task/std::exception_ptr

心不动则不痛 提交于 2021-02-09 11:00:45
问题 I am experiencing some issues with thread sanitizer (TSan) complaining about a data race in some production code where std::packaged_task are handed over to a dispatcher thread by wrapping them in a std::function. For this question I have simplified what it does in production, while triggering TSan. The implementation is similar to the answer given by Anthony Williams in this question (at least that is my understanding): Non-obvious lifetime issue with std::promise and std::future. Note that

Thread sanitizer reports data race when using std::packaged_task/std::exception_ptr

☆樱花仙子☆ 提交于 2021-02-09 11:00:27
问题 I am experiencing some issues with thread sanitizer (TSan) complaining about a data race in some production code where std::packaged_task are handed over to a dispatcher thread by wrapping them in a std::function. For this question I have simplified what it does in production, while triggering TSan. The implementation is similar to the answer given by Anthony Williams in this question (at least that is my understanding): Non-obvious lifetime issue with std::promise and std::future. Note that

How to add breakpoint when thread sanitizer repoorts data-race?

╄→гoц情女王★ 提交于 2021-02-05 11:24:46
问题 There is a similar question for address sanitizers, but for thread sanitizers, it doesn't work, I have tried to break on __sanitizer_print_stack_trace, which don't work either. 回答1: Run the program under GDB, set breakpoints on exit and _exit . On Linux, also set catch syscall exit_group . set halt_on_error=1 in TSAN_OPTIONS to ask thread sanitizer to exit on first error: (gdb) set env TSAN_OPTIONS=halt_on_error=1 (gdb) run ... error should be reported and one of the breakpoints should fire.

How to add breakpoint when thread sanitizer repoorts data-race?

≯℡__Kan透↙ 提交于 2021-02-05 11:24:08
问题 There is a similar question for address sanitizers, but for thread sanitizers, it doesn't work, I have tried to break on __sanitizer_print_stack_trace, which don't work either. 回答1: Run the program under GDB, set breakpoints on exit and _exit . On Linux, also set catch syscall exit_group . set halt_on_error=1 in TSAN_OPTIONS to ask thread sanitizer to exit on first error: (gdb) set env TSAN_OPTIONS=halt_on_error=1 (gdb) run ... error should be reported and one of the breakpoints should fire.

Turning on Thread Sanitizer results in signal SIGABRT

久未见 提交于 2020-01-13 04:52:12
问题 When I create a new Single View App from in Xcode Version 11.3 (11C29) and run it all is ok. When I turn on Thread Sanitize And try to run the very same app, I get Thread 1: signal SIGABRT this is the backtrace (lldb) bt * thread #1, stop reason = signal SIGABRT * frame #0: 0x00007fff523d5bea libsystem_kernel.dylib`__abort_with_payload + 10 frame #1: 0x00007fff523d74f3 libsystem_kernel.dylib`abort_with_payload_wrapper_internal + 80 frame #2: 0x00007fff523d74a3 libsystem_kernel.dylib`abort

Thread sanitizer gives false negative for “function race”

梦想与她 提交于 2019-12-24 23:19:02
问题 Consider the following code: #include <atomic> #include <iostream> #include <thread> std::atomic<int> x, y; std::atomic<int> r1, r2; void f() { r1 = y.load(); x = r1.load(); } void g() { r2 = x.load(); y = 42; } int main() { x = 0; y = 0; r1 = 0; r2 = 0; std::thread t1(f); std::thread t2(g); t1.join(); t2.join(); std::cout << r1 << " " << r2 << std::endl; } If I compile this code with compilers/linux-x86_64-2.10.1/gnu7.1.0/bin/g++ -fsanitize=thread -O3 -std=c++11 main.cpp -o a.out , TSan does

Gcc thread sanitizer false positive only for debug info flag

萝らか妹 提交于 2019-12-22 12:51:03
问题 I am having a problem with Gcc's thread sanitizer that I cannot find on their bugzilla or on stackoverflow so I am unsure if I am missing something or if this really is a bug. If I create a main.cpp file containing: #include <thread> int main(){ std::thread t([](){}); t.join(); return 0;} Now if I compile it using: g++-4.9.2 -std=c++1y -fsanitize=thread -fPIE -pie -o TestProgram main.cpp Running the resulting executable does not yield any problem. Yet if I add the debug info flag: g++-4.9.2

How to use thread-sanitizer of gcc v4.8.1?

让人想犯罪 __ 提交于 2019-12-20 12:48:20
问题 gcc v4.8.x add options for debugging your program: -fsanitize=thread Enable ThreadSanitizer, a fast data race detector. Memory access instructions will be instrumented to detect data race bugs. See http://code.google.com/p/data-race-test/wiki/ThreadSanitizer for more details. My gcc version on Fedora 19: gcc version 4.8.1 20130603 (Red Hat 4.8.1-1) (GCC) Link my program with below command (output of CMake): Linking C executable bin/ftu /usr/bin/cmake -E cmake_link_script CMakeFiles/ftu.dir

Why does ThreadSanitizer report a race with this lock-free example?

試著忘記壹切 提交于 2019-12-18 11:50:19
问题 I've boiled this down to a simple self-contained example. The main thread enqueues 1000 items, and a worker thread tries to dequeue concurrently. ThreadSanitizer complains that there's a race between the read and the write of one of the elements, even though there is an acquire-release memory barrier sequence protecting them. #include <atomic> #include <thread> #include <cassert> struct FakeQueue { int items[1000]; std::atomic<int> m_enqueueIndex; int m_dequeueIndex; FakeQueue() : m

ThreadSanitizer reports “data race on operator delete(void*)” when using embedded reference counter

拥有回忆 提交于 2019-12-07 06:06:04
问题 Please have a look at the following code: #include <pthread.h> #include <boost/atomic.hpp> class ReferenceCounted { public: ReferenceCounted() : ref_count_(1) {} void reserve() { ref_count_.fetch_add(1, boost::memory_order_relaxed); } void release() { if (ref_count_.fetch_sub(1, boost::memory_order_release) == 1) { boost::atomic_thread_fence(boost::memory_order_acquire); delete this; } } private: boost::atomic<int> ref_count_; }; void* Thread1(void* x) { static_cast<ReferenceCounted*>(x)-