| 1 | // REQUIRES: continuous-mode |
| 2 | |
| 3 | // RUN: rm -rf %t.dir |
| 4 | // RUN: %clangxx_pgogen=%t.dir -fprofile-continuous -lpthread %s -o %t.exe -mllvm -disable-vp -fprofile-update=atomic |
| 5 | // RUN: %run %t.exe |
| 6 | // RUN: llvm-profdata show --counts --function=accum %t.dir/default_*.profraw | FileCheck %s |
| 7 | // CHECK: Block counts: [100000, 4] |
| 8 | |
| 9 | #include <thread> |
| 10 | |
| 11 | int x = 0; |
| 12 | void accum(int n) { |
| 13 | for (int i = 0; i < n; i++) |
| 14 | x += i; // don't care about accuracy, no need for atomic. |
| 15 | } |
| 16 | |
| 17 | int main() { |
| 18 | int init_value = 10000; |
| 19 | auto t1 = std::thread(accum, 1*init_value); |
| 20 | auto t2 = std::thread(accum, 2*init_value); |
| 21 | auto t3 = std::thread(accum, 3*init_value); |
| 22 | auto t4 = std::thread(accum, 4*init_value); |
| 23 | |
| 24 | t1.join(); |
| 25 | t2.join(); |
| 26 | t3.join(); |
| 27 | t4.join(); |
| 28 | return !x; |
| 29 | } |
| 30 | |