brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 19c6682 Raw
78 lines · cpp
1// This program is used to generate a core dump for testing multithreading2// support.3 4#include <atomic>5#include <chrono>6#include <cstdint>7#include <thread>8 9std::atomic_int start_counter{3};10 11void pseudobarrier_wait() {12  start_counter--;13  while (start_counter > 0);14}15 16void fcommon(uint32_t a, uint32_t b, uint32_t c, uint32_t d, double fa, double fb, double fc, double fd, bool segv) {17  if (segv) {18    int *foo = nullptr;19    *foo = 0;20  }21  while (1);22}23 24void f1() {25  volatile uint32_t a = 0x01010101;26  volatile uint32_t b = 0x02020202;27  volatile uint32_t c = 0x03030303;28  volatile uint32_t d = 0x04040404;29  volatile double fa = 2.0;30  volatile double fb = 4.0;31  volatile double fc = 8.0;32  volatile double fd = 16.0;33 34  pseudobarrier_wait();35  std::this_thread::sleep_for(std::chrono::milliseconds(200));36  fcommon(a, b, c, d, fa, fb, fc, fd, true);37}38 39void f2() {40  volatile uint32_t a = 0x11111111;41  volatile uint32_t b = 0x12121212;42  volatile uint32_t c = 0x13131313;43  volatile uint32_t d = 0x14141414;44  volatile double fa = 3.0;45  volatile double fb = 6.0;46  volatile double fc = 9.0;47  volatile double fd = 12.0;48 49  pseudobarrier_wait();50  fcommon(a, b, c, d, fa, fb, fc, fd, false);51}52 53void f3() {54  volatile uint32_t a = 0x21212121;55  volatile uint32_t b = 0x22222222;56  volatile uint32_t c = 0x23232323;57  volatile uint32_t d = 0x24242424;58  volatile double fa = 5.0;59  volatile double fb = 10.0;60  volatile double fc = 15.0;61  volatile double fd = 20.0;62 63  pseudobarrier_wait();64  fcommon(a, b, c, d, fa, fb, fc, fd, false);65}66 67int main() {68  std::thread t1{f1};69  std::thread t2{f2};70  std::thread t3{f3};71 72  t3.join();73  t2.join();74  t1.join();75 76  return 0;77}78