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; // Should not reach here. (thread2 should raise SIGILL) |
21 | } |
22 | |
23 | void * |
24 | thread2 () |
25 | { |
26 | raise(SIGILL); // Raise SIGILL |
27 | |
28 | // Synchronize with thread1 and the main thread. |
29 | pseudo_barrier_wait(g_barrier2); // Should not reach here. |
30 | |
31 | // Return |
32 | return NULL; |
33 | } |
34 | |
35 | int main () |
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 | // Create another thread. |
47 | std::thread thread_2(thread2); |
48 | |
49 | // Wait for thread2 to start. |
50 | // Second thread should crash but first thread and main thread may reach here. |
51 | pseudo_barrier_wait(g_barrier2); |
52 | |
53 | return 0; |
54 | } |
55 | |