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