xref: /llvm-project/lldb/test/API/functionalities/thread/multi_break/main.cpp (revision fdea9a4ec9b0d9585b8fe8a612686d9f44f40ddc)
1 // This test is intended to create a situation in which a breakpoint will be
2 // hit in two threads at nearly the same moment.  The expected result is that
3 // the breakpoint in the second thread will be hit while the breakpoint handler
4 // in the first thread is trying to stop all threads.
5 
6 #include "pseudo_barrier.h"
7 #include <thread>
8 
9 pseudo_barrier_t g_barrier;
10 
11 volatile int g_test = 0;
12 
13 void *
thread_func()14 thread_func ()
15 {
16     // Wait until both threads are running
17     pseudo_barrier_wait(g_barrier);
18 
19     // Do something
20     g_test++;       // Set breakpoint here
21 
22     // Return
23     return NULL;
24 }
25 
main()26 int main ()
27 {
28     // Don't let either thread do anything until they're both ready.
29     pseudo_barrier_init(g_barrier, 2);
30 
31     // Create two threads
32     std::thread thread_1(thread_func);
33     std::thread thread_2(thread_func);
34 
35     // Wait for the threads to finish
36     thread_1.join();
37     thread_2.join();
38 
39     return 0;
40 }
41