brintos

brintos / llvm-project-archived public Read only

0
0
Text · 515 B · e8e168a Raw
25 lines · cpp
1// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t && %run %t 2>&1 | FileCheck %s2#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("%d %d\n", v1, v2);21  // CHECK-NOT: ThreadSanitizer: data race22  // CHECK: 42 4223  return 0;24}25