1 //===-- main.cpp ------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This test verifies the correct handling of child thread exits.
15 // Note that although hogging the CPU while waiting for a variable to change
16 // would be terrible in production code, it's great for testing since it
17 // avoids a lot of messy context switching to get multiple threads synchronized.
20 #define pseudo_barrier_wait(bar) \
25 #define pseudo_barrier_init(bar, count) (bar = count)
27 std::atomic_int g_barrier1;
28 std::atomic_int g_barrier2;
29 std::atomic_int g_barrier3;
34 // Synchronize with the main thread.
35 pseudo_barrier_wait(g_barrier1);
37 // Synchronize with the main thread and thread2.
38 pseudo_barrier_wait(g_barrier2);
41 return NULL; // Set second breakpoint here
47 // Synchronize with thread1 and the main thread.
48 pseudo_barrier_wait(g_barrier2);
50 // Synchronize with the main thread.
51 pseudo_barrier_wait(g_barrier3);
59 pseudo_barrier_init(g_barrier1, 2);
60 pseudo_barrier_init(g_barrier2, 3);
61 pseudo_barrier_init(g_barrier3, 2);
64 std::thread thread_1(thread1);
66 // Wait for thread1 to start.
67 pseudo_barrier_wait(g_barrier1);
69 // Create another thread.
70 std::thread thread_2(thread2); // Set first breakpoint here
72 // Wait for thread2 to start.
73 pseudo_barrier_wait(g_barrier2);
75 // Wait for the first thread to finish
78 // Synchronize with the remaining thread
79 pseudo_barrier_wait(g_barrier3); // Set third breakpoint here
81 // Wait for the second thread to finish
84 return 0; // Set fourth breakpoint here