[libc++][NFC] Remove trailing whitespace from release notes
[llvm-project.git] / lldb / test / Shell / Register / Core / Inputs / multithread.cpp
blob19c6682b32cf8c24da68a42b1ca57921d78662d3
1 // This program is used to generate a core dump for testing multithreading
2 // support.
4 #include <atomic>
5 #include <chrono>
6 #include <cstdint>
7 #include <thread>
9 std::atomic_int start_counter{3};
11 void pseudobarrier_wait() {
12 start_counter--;
13 while (start_counter > 0);
16 void 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;
21 while (1);
24 void 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;
34 pseudobarrier_wait();
35 std::this_thread::sleep_for(std::chrono::milliseconds(200));
36 fcommon(a, b, c, d, fa, fb, fc, fd, true);
39 void 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;
49 pseudobarrier_wait();
50 fcommon(a, b, c, d, fa, fb, fc, fd, false);
53 void 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;
63 pseudobarrier_wait();
64 fcommon(a, b, c, d, fa, fb, fc, fd, false);
67 int main() {
68 std::thread t1{f1};
69 std::thread t2{f2};
70 std::thread t3{f3};
72 t3.join();
73 t2.join();
74 t1.join();
76 return 0;