xref: /llvm-project/lldb/test/API/functionalities/thread/ignore_suspended/main.cpp (revision 3b43f006294971b8049d4807110032169780e5b8)
1*3b43f006SIlya Bukonkin // Test simulates situation when suspended thread could stop process
2*3b43f006SIlya Bukonkin // where thread that is a real reason of stop says process
3*3b43f006SIlya Bukonkin // should not stop in it's action handler.
4*3b43f006SIlya Bukonkin 
5*3b43f006SIlya Bukonkin #include <chrono>
6*3b43f006SIlya Bukonkin #include <thread>
7*3b43f006SIlya Bukonkin 
thread1()8*3b43f006SIlya Bukonkin void thread1() {
9*3b43f006SIlya Bukonkin   // Will be suspended at breakpoint stop
10*3b43f006SIlya Bukonkin   // Set first breakpoint here
11*3b43f006SIlya Bukonkin }
12*3b43f006SIlya Bukonkin 
thread2()13*3b43f006SIlya Bukonkin void thread2() {
14*3b43f006SIlya Bukonkin   /*
15*3b43f006SIlya Bukonkin    Prevent threads from stopping simultaneously
16*3b43f006SIlya Bukonkin    */
17*3b43f006SIlya Bukonkin   std::this_thread::sleep_for(std::chrono::seconds(1));
18*3b43f006SIlya Bukonkin   // Set second breakpoint here
19*3b43f006SIlya Bukonkin }
20*3b43f006SIlya Bukonkin 
main()21*3b43f006SIlya Bukonkin int main() {
22*3b43f006SIlya Bukonkin   // Create a thread
23*3b43f006SIlya Bukonkin   std::thread thread_1(thread1);
24*3b43f006SIlya Bukonkin 
25*3b43f006SIlya Bukonkin   // Create another thread.
26*3b43f006SIlya Bukonkin   std::thread thread_2(thread2);
27*3b43f006SIlya Bukonkin 
28*3b43f006SIlya Bukonkin   // Wait for the thread that was not suspeneded
29*3b43f006SIlya Bukonkin   thread_2.join();
30*3b43f006SIlya Bukonkin 
31*3b43f006SIlya Bukonkin   // Wait for thread that was suspended
32*3b43f006SIlya Bukonkin   thread_1.join(); // Set third breakpoint here
33*3b43f006SIlya Bukonkin 
34*3b43f006SIlya Bukonkin   return 0;
35*3b43f006SIlya Bukonkin }
36