TSan can produce false positives in code that uses C++11 threading, as it doesn't see synchronization inside standard library. See http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-February/035408.html for an example of such case. We may build custom TSan-instrumented version libcxx to fight with that. This change adds build rules for libcxx_tsan and integrates it into testing infrastructure. llvm-svn: 208737
25 lines
497 B
C++
25 lines
497 B
C++
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
|
|
#include <stdio.h>
|
|
#include <memory>
|
|
#include <thread>
|
|
|
|
int main() {
|
|
int v1 = 0;
|
|
int v2 = 0;
|
|
std::thread t1;
|
|
std::thread t2;
|
|
|
|
{
|
|
auto thingy = std::make_shared<int>(42);
|
|
t1 = std::thread([thingy, &v1] { v1 = *thingy; });
|
|
t2 = std::thread([thingy, &v2] { v2 = *thingy; });
|
|
}
|
|
|
|
t1.join();
|
|
t2.join();
|
|
printf("%d %d\n", v1, v2);
|
|
// CHECK-NOT: ThreadSanitizer: data race
|
|
// CHECK: 42 42
|
|
return 0;
|
|
}
|