brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 6c60a40 Raw
66 lines · cpp
1// This test verifies the correct handling of child thread exits.2 3#include "pseudo_barrier.h"4#include <thread>5 6pseudo_barrier_t g_barrier1;7pseudo_barrier_t g_barrier2;8pseudo_barrier_t g_barrier3;9 10void *11thread1 ()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    // Return20    return NULL;                                      // Set second breakpoint here21}22 23void *24thread2 ()25{26    // Synchronize with thread1 and the main thread.27    pseudo_barrier_wait(g_barrier2);28 29    // Synchronize with the main thread.30    pseudo_barrier_wait(g_barrier3);31 32    // Return33    return NULL;34}35 36int main ()37{38    pseudo_barrier_init(g_barrier1, 2);39    pseudo_barrier_init(g_barrier2, 3);40    pseudo_barrier_init(g_barrier3, 2);41 42    // Create a thread.43    std::thread thread_1(thread1);44 45    // Wait for thread1 to start.46    pseudo_barrier_wait(g_barrier1);47 48    // Create another thread.49    std::thread thread_2(thread2);  // Set first breakpoint here50 51    // Wait for thread2 to start.52    pseudo_barrier_wait(g_barrier2);53 54    // Wait for the first thread to finish55    thread_1.join();56 57    // Synchronize with the remaining thread58    int dummy = 47;                   // Set third breakpoint here59    pseudo_barrier_wait(g_barrier3);60 61    // Wait for the second thread to finish62    thread_2.join();63 64    return 0;                                         // Set fourth breakpoint here65}66