1*635f03feSJim Ingham // This test is intended to create a situation in which two threads are stopped 2*635f03feSJim Ingham // at a breakpoint and the debugger issues a step-out command. 3*635f03feSJim Ingham 4*635f03feSJim Ingham #include "pseudo_barrier.h" 5*635f03feSJim Ingham #include <thread> 6*635f03feSJim Ingham 7*635f03feSJim Ingham pseudo_barrier_t g_barrier; 8*635f03feSJim Ingham 9*635f03feSJim Ingham volatile int g_test = 0; 10*635f03feSJim Ingham stop_here()11*635f03feSJim Inghamvoid stop_here() { 12*635f03feSJim Ingham g_test += 5; // Set breakpoint here 13*635f03feSJim Ingham } 14*635f03feSJim Ingham recurse_a_bit_1(int count)15*635f03feSJim Inghamvoid recurse_a_bit_1(int count) { 16*635f03feSJim Ingham if (count == 50) 17*635f03feSJim Ingham stop_here(); 18*635f03feSJim Ingham else 19*635f03feSJim Ingham recurse_a_bit_1(++count); 20*635f03feSJim Ingham } 21*635f03feSJim Ingham recurse_a_bit_2(int count)22*635f03feSJim Inghamvoid recurse_a_bit_2(int count) { 23*635f03feSJim Ingham if (count == 50) 24*635f03feSJim Ingham stop_here(); 25*635f03feSJim Ingham else 26*635f03feSJim Ingham recurse_a_bit_2(++count); 27*635f03feSJim Ingham } 28*635f03feSJim Ingham thread_func_1()29*635f03feSJim Inghamvoid *thread_func_1() { 30*635f03feSJim Ingham // Wait until both threads are running 31*635f03feSJim Ingham pseudo_barrier_wait(g_barrier); 32*635f03feSJim Ingham 33*635f03feSJim Ingham // Start the recursion: 34*635f03feSJim Ingham recurse_a_bit_1(0); 35*635f03feSJim Ingham 36*635f03feSJim Ingham // Return 37*635f03feSJim Ingham return NULL; 38*635f03feSJim Ingham } 39*635f03feSJim Ingham thread_func_2()40*635f03feSJim Inghamvoid *thread_func_2() { 41*635f03feSJim Ingham // Wait until both threads are running 42*635f03feSJim Ingham pseudo_barrier_wait(g_barrier); 43*635f03feSJim Ingham 44*635f03feSJim Ingham // Start the recursion: 45*635f03feSJim Ingham recurse_a_bit_2(0); 46*635f03feSJim Ingham 47*635f03feSJim Ingham // Return 48*635f03feSJim Ingham return NULL; 49*635f03feSJim Ingham } 50*635f03feSJim Ingham main()51*635f03feSJim Inghamint main() { 52*635f03feSJim Ingham // Don't let either thread do anything until they're both ready. 53*635f03feSJim Ingham pseudo_barrier_init(g_barrier, 2); 54*635f03feSJim Ingham 55*635f03feSJim Ingham // Create two threads 56*635f03feSJim Ingham std::thread thread_1(thread_func_1); 57*635f03feSJim Ingham std::thread thread_2(thread_func_2); 58*635f03feSJim Ingham 59*635f03feSJim Ingham // Wait for the threads to finish 60*635f03feSJim Ingham thread_1.join(); 61*635f03feSJim Ingham thread_2.join(); 62*635f03feSJim Ingham 63*635f03feSJim Ingham return 0; 64*635f03feSJim Ingham } 65