Files
clang-p2996/compiler-rt/test/profile/ContinuousSyncMode/multi-threaded.cpp
NAKAMURA Takumi de294c968b [profile] Enable testing Continuous mode on Linux (#121238)
Based on #115987, with the introduction of `REQUIRES: continuous-mode`.
Also Linux assumes `runtime_reloc`.

FIXME: image-with-no-counters.c is still excluded.
2024-12-29 12:02:13 +09:00

30 lines
763 B
C++

// 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;
}