]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/thread/main.cpp
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / thread / main.cpp
1 #include <condition_variable>
2 #include <mutex>
3 #include <thread>
4
5 std::mutex mutex;
6 std::condition_variable cond;
7
8 void *
9 thread3(void *input)
10 {
11     std::unique_lock<std::mutex> lock(mutex);
12     cond.notify_all(); // Set break point at this line.
13     return NULL;
14 }
15
16 void *
17 thread2(void *input)
18 {
19     std::unique_lock<std::mutex> lock(mutex);
20     cond.notify_all();
21     cond.wait(lock);
22     return NULL;
23 }
24
25 void *
26 thread1(void *input)
27 {
28     std::thread thread_2(thread2, nullptr);
29     thread_2.join();
30
31     return NULL;
32 }
33
34 int main()
35 {
36     std::unique_lock<std::mutex> lock(mutex);
37
38     std::thread thread_1(thread1, nullptr);
39     cond.wait(lock);
40
41     std::thread thread_3(thread3, nullptr);
42     cond.wait(lock);
43
44     lock.unlock();
45
46     thread_1.join();
47     thread_3.join();
48
49     return 0;
50 }