int main () { // The first barrier waits for the non-joining threads to start. // This thread will also participate in that barrier. // The idea here is to guarantee that the joining thread will be // last in the internal list maintained by the debugger. pseudo_barrier_init(g_barrier1, 5); // The second barrier keeps the waiting threads around until the breakpoint // has been passed. pseudo_barrier_init(g_barrier2, 4); // Create a thread to hit the breakpoint std::thread thread_1(break_thread_func); // Create more threads to slow the debugger down during processing. std::thread thread_2(wait_thread_func); std::thread thread_3(wait_thread_func); std::thread thread_4(wait_thread_func); // Create a thread to join the breakpoint thread std::thread thread_5(join_thread_func, &thread_1); // Wait for the threads to finish thread_5.join(); // implies thread_1 is already finished thread_4.join(); thread_3.join(); thread_2.join(); return 0; }
int main () { // Use a simple count to simulate a barrier. pseudo_barrier_init(g_barrier, 2); // Create a thread to hit the breakpoint. std::thread thread_1(step_thread_func); // Wait until the step thread is stepping while (g_test < 1) do_nothing(); // Create a thread to exit while we're stepping. std::thread thread_2(create_thread_func, &thread_1); // Wait until that thread is started pseudo_barrier_wait(g_barrier); // Let the stepping thread know the other thread is there g_thread_created = 1; // Wait for the threads to finish. thread_2.join(); thread_1.join(); return 0; }
int main () { pthread_t thread_1; pthread_t thread_2; // Synchronize thread start so that doesn't happen during stepping. pseudo_barrier_init(g_barrier, 2); // Create a thread to hit the breakpoint. pthread_create (&thread_1, NULL, step_thread_func, NULL); // Create a thread to exit while we're stepping. pthread_create (&thread_2, NULL, exit_thread_func, NULL); // Wait for the exit thread to finish. pthread_join(thread_2, NULL); // Let the stepping thread know the other thread is gone. g_thread_exited = 1; // Wait for the stepping thread to finish. pthread_join(thread_1, NULL); return 0; }
int main () { // Don't let either thread do anything until they're both ready. pseudo_barrier_init(g_barrier, 2); // Create two threads std::thread thread_1(thread_func); std::thread thread_2(thread_func); // Wait for the threads to finish thread_1.join(); thread_2.join(); return 0; }
int main () { pthread_t thread_1; pthread_t thread_2; // Don't let either thread do anything until they're both ready. pseudo_barrier_init(g_barrier, 2); // Create two threads pthread_create (&thread_1, NULL, thread_func, NULL); pthread_create (&thread_2, NULL, thread_func, NULL); // Wait for the threads to finish pthread_join(thread_1, NULL); pthread_join(thread_2, NULL); return 0; }