0

这是一个小示例程序:

#include <execution>
#include <vector>

using namespace std;

int main() {
  vector<const char *> my_vector{"some", "words", "here"};
  for_each(execution::par, my_vector.begin(), my_vector.end(),
           [&](const char *s) {
             // do nothing here
           });
}

我编译它(在当前的 Arch Linux 上):

g++ -std=c++20 -ltbb -fsanitize=thread test.cc

我无法想象这个程序是如何引起数据竞争的,因为它没有写入,但 TSan 对此非常不满。错误的洪流始于:

WARNING: ThreadSanitizer: data race (pid=124291)                                                                                                                                                 Write of size 8 at 0x7f620b79b900 by thread T6:                                                                                                                                                  #0 memset /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:778 (libtsan.so.0+0x37449)                                                                    
    #1 memset /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:776 (libtsan.so.0+0x37449)                                                                    
    #2 <null> <null> (libtbbmalloc.so.2+0x13ed6)

这可能只是 TSan 的误报吗?

4

0 回答 0