Home > Blockchain >  Thread Sanitizer - How to interpret the Read vs Previous Write warning
Thread Sanitizer - How to interpret the Read vs Previous Write warning

Time:11-18

I am running a program with thread sanitizers and wonder how to interpret the following warning:

==================
WARNING: ThreadSanitizer: data race (pid=2788668)
  Read of size 4 at 0x7f7eefc4e298 by main thread:
[Stacktrace follows...]
  Previous write of size 8 at 0x7f7eefc4e298 by thread T27:
[Stacktrace follows...]
  Location is heap block of size 307272 at 0x7f7eefc1c000 allocated by thread T27
[Stacktrace follows...]
  Thread T27 (tid=2790352, running) created by main thread at:
[Stacktrace follows...]
==================

I am interpreting this message as just saying that the main thread read memory written to previously by a different thread. The different thread was created by the main thread and this different thread also allocated the memory. Is this correct? If so, is there a way to suppress this particular warning in the following runs?

CodePudding user response:

The warning is a real error (unless it is a false positive).

Thread T27 wrote 8 bytes to address 0x7f7eefc4e298 and main thread read the first 4 bytes of that later without locking (as far as the sanitizer could tell). This is a race condition and undefined behaviour.

In other words, access to 0x7f7eefc4e298 is not protected by locks or other synchronization primitives. Is that the case?

If you insist, there is a way how to silence them, create a supp.txt file with:

# Silences all races originating in bar_function
race:foo_namespace::bar_function

Then run your test with TSAN_OPTIONS="suppressions=supp.txt" environment variable set. There is a sparse documentation for the format of the suppresion file. Another compile-time option using -fsanitize-ignorelist which should disable the instrumentation itself.

  • Related