1 | // This test verifies the correct handling of child thread exits. |
2 | |
3 | #include "pseudo_barrier.h" |
4 | #include <thread> |
5 | #include <csignal> |
6 | |
7 | pseudo_barrier_t g_barrier1; |
8 | pseudo_barrier_t g_barrier2; |
9 | |
10 | void * |
11 | thread1 () |
12 | { |
13 | // Synchronize with the main thread. |
14 | pseudo_barrier_wait(g_barrier1); |
15 | |
16 | // Synchronize with the main thread and thread2. |
17 | pseudo_barrier_wait(g_barrier2); |
18 | |
19 | // Return |
20 | return NULL; |
21 | } |
22 | |
23 | void * |
24 | thread2 () |
25 | { |
26 | |
27 | // Synchronize with thread1 and the main thread. |
28 | pseudo_barrier_wait(g_barrier2); // Should not reach here. |
29 | |
30 | // Return |
31 | return NULL; |
32 | } |
33 | |
34 | int main () |
35 | { |
36 | |
37 | pseudo_barrier_init(g_barrier1, 2); |
38 | pseudo_barrier_init(g_barrier2, 3); |
39 | |
40 | // Create a thread. |
41 | std::thread thread_1(thread1); |
42 | |
43 | // Wait for thread1 to start. |
44 | pseudo_barrier_wait(g_barrier1); |
45 | |
46 | // Wait for thread1 to start. |
47 | std::thread thread_2(thread2); |
48 | |
49 | // Thread 2 is waiting for another thread to reach the barrier. |
50 | // This should have for ever. (So we can run gcore against this process.) |
51 | thread_2.join(); |
52 | |
53 | return 0; |
54 | } |
55 | |