| 1 | // RUN: %clangxx_tsan %s -o %t |
| 2 | // RUN: %run %t 2>&1 | FileCheck %s |
| 3 | |
| 4 | #include <iostream> |
| 5 | #include <future> |
| 6 | #include <vector> |
| 7 | |
| 8 | int main(int argc, const char *argv[]) { |
| 9 | fprintf(stderr, "Hello world.\n" ); |
| 10 | |
| 11 | auto my_task = [] { return 42; }; |
| 12 | |
| 13 | std::vector<std::thread> threads; |
| 14 | |
| 15 | for (int i = 0; i < 100; i++) { |
| 16 | std::packaged_task<int(void)> task(my_task); |
| 17 | std::future<int> future = task.get_future(); |
| 18 | threads.push_back(std::thread(std::move(task))); |
| 19 | } |
| 20 | |
| 21 | for (auto &t : threads) { |
| 22 | t.join(); |
| 23 | } |
| 24 | |
| 25 | fprintf(stderr, "Done.\n" ); |
| 26 | } |
| 27 | |
| 28 | // CHECK: Hello world. |
| 29 | // CHECK-NOT: WARNING: ThreadSanitizer |
| 30 | // CHECK: Done. |
| 31 | |