1// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t && %run %t 2>&1 | FileCheck %s
2#include <stdio.h>
3#include <memory>
4#include <thread>
5
6int main() {
7 int v1 = 0;
8 int v2 = 0;
9 std::thread t1;
10 std::thread t2;
11
12 {
13 auto thingy = std::make_shared<int>(42);
14 t1 = std::thread([thingy, &v1] { v1 = *thingy; });
15 t2 = std::thread([thingy, &v2] { v2 = *thingy; });
16 }
17
18 t1.join();
19 t2.join();
20 printf(format: "%d %d\n", v1, v2);
21 // CHECK-NOT: ThreadSanitizer: data race
22 // CHECK: 42 42
23 return 0;
24}
25

source code of compiler-rt/test/tsan/libcxx/std_shared_ptr.cpp