Files
clang-p2996/compiler-rt/test/tsan/libcxx/std_shared_ptr.cc
Alexey Samsonov 5716928ae2 [TSan] Build TSan-instrumented version of libcxx and use it in lit tests.
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
2014-05-13 22:30:16 +00:00

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;
}