thread-sanitizer

Gcc thread sanitizer false positive only for debug info flag

折月煮酒 提交于 2019-12-06 10:52:15
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 -std=c++1y -fsanitize=thread -g -fPIE -pie -o TestProgram main.cpp then the thread sanitizer detects a

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

余生颓废 提交于 2019-12-05 10:19:15
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)->release(); return NULL; } void* Thread2(void* x) { static_cast<ReferenceCounted*>(x)->release(); return

Can I use Thread Sanitizer for OpenMP programs?

て烟熏妆下的殇ゞ 提交于 2019-11-30 03:34:42
问题 Consider the following example: #include <iostream> int main () { int i = 0; #pragma omp parallel { #pragma omp critical { ++i; } } std::cout << i; } Compiling with g++ -fopenmp -fsanitize=thread and running yields WARNING: ThreadSanitizer: data race (pid=9576) Read of size 4 at 0x7ffdc170f600 by thread T1: #0 main._omp_fn.0 (a.out+0x000000400d20) #1 gomp_thread_start /build/gcc/src/gcc-5.2.0/libgomp/team.c:118 (libgomp.so.1+0x00000000f42d) Previous write of size 4 at 0x7ffdc170f600 by thread