]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/thread/thread_exit/main.cpp
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / thread / thread_exit / main.cpp
1 //===-- main.cpp ------------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // This test verifies the correct handling of child thread exits.
11
12 #include <atomic>
13 #include <thread>
14
15 pseudo_barrier_t g_barrier1;
16 pseudo_barrier_t g_barrier2;
17 pseudo_barrier_t g_barrier3;
18
19 void *
20 thread1 ()
21 {
22     // Synchronize with the main thread.
23     pseudo_barrier_wait(g_barrier1);
24
25     // Synchronize with the main thread and thread2.
26     pseudo_barrier_wait(g_barrier2);
27
28     // Return
29     return NULL;                                      // Set second breakpoint here
30 }
31
32 void *
33 thread2 ()
34 {
35     // Synchronize with thread1 and the main thread.
36     pseudo_barrier_wait(g_barrier2);
37
38     // Synchronize with the main thread.
39     pseudo_barrier_wait(g_barrier3);
40
41     // Return
42     return NULL;
43 }
44
45 int main ()
46 {
47     pseudo_barrier_init(g_barrier1, 2);
48     pseudo_barrier_init(g_barrier2, 3);
49     pseudo_barrier_init(g_barrier3, 2);
50
51     // Create a thread.
52     std::thread thread_1(thread1);
53
54     // Wait for thread1 to start.
55     pseudo_barrier_wait(g_barrier1);
56
57     // Create another thread.
58     std::thread thread_2(thread2);  // Set first breakpoint here
59
60     // Wait for thread2 to start.
61     pseudo_barrier_wait(g_barrier2);
62
63     // Wait for the first thread to finish
64     thread_1.join();
65
66     // Synchronize with the remaining thread
67     pseudo_barrier_wait(g_barrier3);                  // Set third breakpoint here
68
69     // Wait for the second thread to finish
70     thread_2.join();
71
72     return 0;                                         // Set fourth breakpoint here
73 }