Questions tagged [thread-sanitizer]

ThreadSanitizer (TSan) is a data race detector for C/C++ programs.

ThreadSanitizer (aka tsan, not "Thread Sanitizer") is a data race detector for C/C++ programs.

See also:

91 questions
5
votes
0 answers

TSan race disappears with alignas(32)

I have an implementation of a lockfree queue, which I believe to be correct (or at least data race-free): #include #include #include #include struct Job { int id; int data; }; class JobQueue { using…
angelsl
  • 395
  • 3
  • 14
5
votes
2 answers

Thread safety of std::cout insertion operator

I've always thought that using std::cout << something was thread safe. For this little example #include #include void f() { std::cout << "Hello from f\n"; } void g() { std::cout << "Hello from g\n"; } int main() { …
Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
5
votes
3 answers

Xcode 11.2.1 Thread Sanitizer abort_with_payload

I'm trying to use the Thread Sanitizer in Xcode 11.2.1 but whenever the app launches (just a single view app from Xcode's template, nothing added) it hits __abort_with_payload: libsystem_kernel.dylib`__abort_with_payload: 0x7fff51b73be0 <+0>: …
CMash
  • 1,987
  • 22
  • 35
5
votes
1 answer

GCC 4.9.1 ThreadSanitizer "As if synchronized via sleep"

I'm working on cleaning up ThreadSanitizer warnings in a largeish project. In particular in this exact case, there is a spawned thread which reads from a file, producer. Then there are one or more decompression threads as part of a thread pool.…
inetknght
  • 4,300
  • 1
  • 26
  • 52
5
votes
2 answers

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

Please have a look at the following code: #include #include class ReferenceCounted { public: ReferenceCounted() : ref_count_(1) {} void reserve() { ref_count_.fetch_add(1,…
Adam Romanek
  • 1,809
  • 1
  • 19
  • 36
5
votes
2 answers

How to use clang thread sanitizer on OSX?

I am trying to use --thread-sanitizer option of clang on OSX: $ clang++ -fthread-sanitizer -fpic tsan1.cc Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn) Target: x86_64-apple-darwin12.3.0 Thread model: posix [...] clang -cc1 version…
Maxim Razin
  • 9,114
  • 7
  • 34
  • 33
4
votes
2 answers

Segfault in TSAN in Boost CI - Need the help of an expert

I am debugging A segfault reported by TSAN in the CI of Boost.Beast. I strongly believe it to be a false positive, but I don't know what to look for in order to suppress it. It seems to me from the stack trace that the code is correctly…
Richard Hodges
  • 68,278
  • 7
  • 90
  • 142
4
votes
1 answer

How do I annotate seq-cst atomic fences for the thread sanitizer?

I learned that TSAN doesn't understand std::atomic_thread_fence, and to fix it, you need to tell TSAN which atomic variables are affected by the fence, by putting __tsan_acquire(void *) and __tsan_release(void *) next to it (for acquire and release…
HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
4
votes
1 answer

How to find line number in ThreadSanitizer stack trace

I compile using Clang with -g3 and -O1 flags, but TSan complains that it found a data-race and it outputs a totally obscure stack trace with no clear line numbers. How to find line numbers in this case? Output on Pastebin since Stack Overflow…
jeffbRTC
  • 1,941
  • 10
  • 29
4
votes
2 answers

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

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 doesn't work either.
prehistoricpenguin
  • 6,130
  • 3
  • 25
  • 42
4
votes
0 answers

Dealing with a tsan lock-order-inversion false positive

I have code which is identified by tsan as lock-order-inversion. It is a false positive. I know I can use suppression files to prevent this but I wonder whether I can do something with my code so that my intention is clearer and it doesn't get…
Borislav Stanimirov
  • 1,609
  • 12
  • 23
4
votes
1 answer

How to detect thread sanitizer for gcc 5

How can I detect whether thread sanitizer has been turned on for a build using gcc 5? Neither one of the two between __has_feature(thread_sanitizer) nor __SANITIZE_THREAD__ work #include using std::cout; using std::endl; int main() { …
Curious
  • 20,870
  • 8
  • 61
  • 146
4
votes
1 answer

Missing libclang_rt.tsan-x86_64.a on clang-7.0

I am trying to hunt down some deadlock in multi-threaded code which uses a condition variable. Somebody advised using thread sanitizer. So I compiled LLVM from source and enabled thread sanitizer LLVM built fine, but when I try to build my project…
Dženan
  • 3,329
  • 3
  • 31
  • 44
4
votes
1 answer

write-write data race from a std::set insert() and find()?

To experiment with the thread-sanitizer, I created a tiny C++ program which by purpose contains a data race. Indeed, tsan does detect the error, great! However I am puzzled by the generated message... It reports a write-write data race, where I…
Jos v E
  • 165
  • 1
  • 5
3
votes
0 answers

clang thread sanitizer reports issues when using conditon variables

Here is a simple example for using std::condition_variable. When using clang+tsan for building the following code, #include #include #include #include #include #include class…