xref: /llvm-project/compiler-rt/test/profile/ContinuousSyncMode/multi-threaded.cpp (revision de294c968bf292794ca9f0a6a481d3dff3bcc2eb)
1 // REQUIRES: continuous-mode
2 
3 // RUN: rm -f %t.profraw
4 // RUN: %clangxx_pgogen_cont -lpthread %s -o %t.exe -mllvm -disable-vp -fprofile-update=atomic
5 // RUN: env LLVM_PROFILE_FILE="%c%t.profraw" %run %t.exe
6 // RUN: llvm-profdata show --counts --function=accum  %t.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