Thread Sanitizer - 如何解释 Read vs Previous Write 警告
Thread Sanitizer - How to interpret the Read vs Previous Write 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...]
==================
我将此消息解释为只是说主线程读取之前由不同线程写入的内存。不同的线程是由主线程创建的,这个不同的线程也分配了内存。这个对吗?如果是这样,有没有办法在接下来的运行中抑制这个特定的警告?
警告是真正的错误(除非是误报)。
线程 T27 向地址 0x7f7eefc4e298
写入了 8 个字节,主线程随后 在没有锁定的情况下读取了前 4 个字节 (就消毒程序而言)。这是一个竞争条件和未定义的行为。
换句话说,对 0x7f7eefc4e298
的访问不受锁或其他同步原语的保护。是这样吗?
如果你坚持,有办法让他们沉默,创建一个 supp.txt
文件:
# Silences all races originating in bar_function
race:foo_namespace::bar_function
然后 运行 您的测试设置了 TSAN_OPTIONS="suppressions=supp.txt"
环境变量。有一个 sparse documentation for the format of the suppresion file. Another compile-time option 使用 -fsanitize-ignorelist
应该禁用检测本身。
我是 运行 一个带有线程清理程序的程序,想知道如何解释以下警告:
==================
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...]
==================
我将此消息解释为只是说主线程读取之前由不同线程写入的内存。不同的线程是由主线程创建的,这个不同的线程也分配了内存。这个对吗?如果是这样,有没有办法在接下来的运行中抑制这个特定的警告?
警告是真正的错误(除非是误报)。
线程 T27 向地址 0x7f7eefc4e298
写入了 8 个字节,主线程随后 在没有锁定的情况下读取了前 4 个字节 (就消毒程序而言)。这是一个竞争条件和未定义的行为。
换句话说,对 0x7f7eefc4e298
的访问不受锁或其他同步原语的保护。是这样吗?
如果你坚持,有办法让他们沉默,创建一个 supp.txt
文件:
# Silences all races originating in bar_function
race:foo_namespace::bar_function
然后 运行 您的测试设置了 TSAN_OPTIONS="suppressions=supp.txt"
环境变量。有一个 sparse documentation for the format of the suppresion file. Another compile-time option 使用 -fsanitize-ignorelist
应该禁用检测本身。