41 lines · c
1#include <errno.h>2#include <pthread.h>3#include <stdio.h>4#include <unistd.h>5 6static unsigned int g_timeout = 1000000;7 8extern int usleep(unsigned int);9 10int function_to_call() {11 12 errno = 0;13 while (1) {14 int result = usleep(g_timeout);15 if (errno != EINTR)16 break;17 }18 19 pthread_exit((void *)10);20 21 return 20; // Prevent warning22}23 24void *exiting_thread_func(void *unused) {25 function_to_call(); // Break here and cause the thread to exit26 return NULL;27}28 29int main() {30 void *exit_ptr;31 pthread_t exiting_thread;32 33 pthread_create(&exiting_thread, NULL, exiting_thread_func, NULL);34 35 pthread_join(exiting_thread, &exit_ptr);36 int ret_val = (int)exit_ptr;37 usleep(g_timeout * 4); // Make sure in the "run all threads" case38 // that we don't run past our breakpoint.39 return ret_val; // Break here to make sure the thread exited.40}41