]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/gcore/main.cpp
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / postmortem / elf-core / gcore / 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 #include <csignal>
15
16 pseudo_barrier_t g_barrier1;
17 pseudo_barrier_t g_barrier2;
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;
30 }
31
32 void *
33 thread2 ()
34 {
35
36   // Synchronize with thread1 and the main thread.
37   pseudo_barrier_wait(g_barrier2); // Should not reach here.
38
39   // Return
40   return NULL;
41 }
42
43 int main ()
44 {
45
46   pseudo_barrier_init(g_barrier1, 2);
47   pseudo_barrier_init(g_barrier2, 3);
48
49   // Create a thread.
50   std::thread thread_1(thread1);
51
52   // Wait for thread1 to start.
53   pseudo_barrier_wait(g_barrier1);
54
55   // Wait for thread1 to start.
56   std::thread thread_2(thread2);
57
58   // Thread 2 is waiting for another thread to reach the barrier.
59   // This should have for ever. (So we can run gcore against this process.)
60   thread_2.join();
61
62   return 0;
63 }