blob: e8e168a682fa97f70a98e44665663c71aeafcbfa [file] [log] [blame]
Jonas Hahnfeldfb76b332019-02-17 18:47:33 +00001// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t && %run %t 2>&1 | FileCheck %s
Alexey Samsonov7986f6e2014-05-13 22:30:16 +00002#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 race
22 // CHECK: 42 42
23 return 0;
24}