summaryrefslogtreecommitdiff
path: root/compiler-rt/test/profile/ContinuousSyncMode/multi-threaded.cpp
blob: aa0a46e0fc396d589cea57e64e643f140416bacb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// REQUIRES: continuous-mode

// RUN: rm -f %t.profraw
// RUN: %clangxx_pgogen_cont -lpthread %s -o %t.exe -mllvm -disable-vp -fprofile-update=atomic
// RUN: env LLVM_PROFILE_FILE="%c%t.profraw" %run %t.exe
// RUN: llvm-profdata show --counts --function=accum  %t.profraw | FileCheck %s
// CHECK:    Block counts: [100000, 4]

#include <thread>

int x = 0;
void accum(int n) {
  for (int i = 0; i < n; i++)
    x += i; // don't care about accuracy, no need for atomic.
}

int main() {
  int init_value = 10000;
  auto t1 = std::thread(accum, 1*init_value);
  auto t2 = std::thread(accum, 2*init_value);
  auto t3 = std::thread(accum, 3*init_value);
  auto t4 = std::thread(accum, 4*init_value);

  t1.join();
  t2.join();
  t3.join();
  t4.join();
  return !x;
}