1 //===-- main.cpp ------------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // This test verifies the correct handling of child thread exits. 10 11 #include "pseudo_barrier.h" 12 #include <thread> 13 14 pseudo_barrier_t g_barrier1; 15 pseudo_barrier_t g_barrier2; 16 pseudo_barrier_t g_barrier3; 17 18 void * 19 thread1 () 20 { 21 // Synchronize with the main thread. 22 pseudo_barrier_wait(g_barrier1); 23 24 // Synchronize with the main thread and thread2. 25 pseudo_barrier_wait(g_barrier2); 26 27 // Return 28 return NULL; // Set second breakpoint here 29 } 30 31 void * 32 thread2 () 33 { 34 // Synchronize with thread1 and the main thread. 35 pseudo_barrier_wait(g_barrier2); 36 37 // Synchronize with the main thread. 38 pseudo_barrier_wait(g_barrier3); 39 40 // Return 41 return NULL; 42 } 43 44 int main () 45 { 46 pseudo_barrier_init(g_barrier1, 2); 47 pseudo_barrier_init(g_barrier2, 3); 48 pseudo_barrier_init(g_barrier3, 2); 49 50 // Create a thread. 51 std::thread thread_1(thread1); 52 53 // Wait for thread1 to start. 54 pseudo_barrier_wait(g_barrier1); 55 56 // Create another thread. 57 std::thread thread_2(thread2); // Set first breakpoint here 58 59 // Wait for thread2 to start. 60 pseudo_barrier_wait(g_barrier2); 61 62 // Wait for the first thread to finish 63 thread_1.join(); 64 65 // Synchronize with the remaining thread 66 int dummy = 47; // Set third breakpoint here 67 pseudo_barrier_wait(g_barrier3); 68 69 // Wait for the second thread to finish 70 thread_2.join(); 71 72 return 0; // Set fourth breakpoint here 73 } 74