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
27
votes
2 answers

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

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,…
Cameron
  • 96,106
  • 25
  • 196
  • 225
19
votes
1 answer

Why does the thread sanitizer complain about acquire/release thread fences?

I'm learning about different memory orders. I have this code, which works and passes GCC's and Clang's thread sanitizers: #include #include #include int state = 0; std::atomic_int a = 0; void foo(int from, int to)…
HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
18
votes
2 answers

Where is the data race in this simple c++ code

Both clang++ and g++ sanitizers produce similar warning about data race for this simple code. Is it a false alarm? What is the problem? Code: #include struct A { void operator()() { } }; struct B { void operator()() { …
16
votes
1 answer

How can I suppress Thread Sanitizer warnings in Xcode from an external library?

Xcode 8 incorporates the Thread Sanitizer, a tool for detecting race conditions and other threading-related issues. I'm trying to run this against a project of mine, and am detecting many issues with a third-party binary library. These issues are…
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
15
votes
2 answers

Can I use Thread Sanitizer for OpenMP programs?

Consider the following example: #include int main () { int i = 0; #pragma omp parallel { #pragma omp critical { ++i; } } std::cout << i; } Compiling with g++ -fopenmp…
Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
14
votes
3 answers

C++11 (g++ thread sanitized) Ordering nonatomic operations with atomics (false positive?)

I am experimenting with g++ and thread sanitizer and I think I am getting false positives. Is this true, or am I making some big mistake? Program (cut&paste from Anthony Williams: C++ Concurrency in Action, page 145, listing 5.13) #include…
Os3
  • 143
  • 8
14
votes
1 answer

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

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…
husthl
  • 487
  • 1
  • 3
  • 11
13
votes
1 answer

Avoiding false positives with clang's ThreadSanitizer and TBB

Has anyone tried clang's ThreadSanitizer with Intel Threading Building Blocks (TBB)? My experience so far was that you will get a lot of warnings, even for relatively simple examples. Unfortunately, many of them seem to be false positives. In this…
Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239
10
votes
0 answers

Data race reported in Boost lockfree queue by TSan

I'm running the MPMC example given in boost lockfree queue documentation with thread sanitizer and to my surprise this basic example contains data races as per TSan. Any idea what might be wrong? OS: Red Hat Enterprise Linux Server release 7.7 /…
Vishal Sharma
  • 1,670
  • 20
  • 55
8
votes
1 answer

Where is the race in this thread sanitzer warning?

The below code produce a warning when running with thread sanitizer on macOS. I can't see where the race is. The control block of shared_ptr and weak_ptr is thread safe, and pushing and popping from the std::queue is done with a lock held. #include…
tuple_cat
  • 1,165
  • 2
  • 7
  • 22
7
votes
1 answer

How do I avoid or suppress the race in this lock free stack?

I'm using a lock free stack (via tagged pointers) to manage a pool of small blocks of memory. The list nodes are created and destroyed in-place when the blocks are inserted into, and removed from, the pool. This is a very simplified test program,…
Alex K
  • 171
  • 3
7
votes
1 answer

what are the valid sanitizer suppression strings for gcc?

When using sanitizers with gcc one can provide a list of exceptions/suppressions to deal with false positives and such. the suppression file format is poorly documented. Each suppression is of the form name_of_check:path_or_name What are the valid…
6
votes
2 answers

Can't run iOS app on simulator in Xcode 10.2

In Xcode 10.2 I can no longer run my app on a simulator with thread sanitizer enabled. I get the error This app could not be installed at this time. WatchKit v3 app has disallowed Info.plist key: NSBuiltWithThreadSanitizer My app includes a watch…
Max
  • 21,123
  • 5
  • 49
  • 71
6
votes
0 answers

How can I make thread sanitizer "more accurate"?

According to the thread-sanitizer docs: ThreadSanitizer uses more real memory than a native run. At the default settings the memory overhead is 5x plus 1Mb per each thread. Settings with 3x (less accurate analysis) and 9x (more accurate analysis)…
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
5
votes
0 answers

C++ how to get the variable(s) by its address

context: I am using thread sanitizer for my program, and it shows my program has data race. I'm 100% sure why (maybe there's too much memory access), thread sanitizer doesn't give out the exact stacktrace for the invalid access. There's…
Tinyden
  • 524
  • 4
  • 13
1
2 3 4 5 6 7