Jonas Hahnfeld | fb76b33 | 2019-02-17 18:47:33 +0000 | [diff] [blame] | 1 | // RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t && %run %t 2>&1 | FileCheck %s |
Alexey Samsonov | 7986f6e | 2014-05-13 22:30:16 +0000 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <memory> |
| 4 | #include <thread> |
| 5 | |
| 6 | int 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 | } |