1 #include <errno.h> 2 #include <pthread.h> 3 #include <stdio.h> 4 #include <unistd.h> 5 6 static unsigned int g_timeout = 1000000; 7 8 extern int usleep(unsigned int); 9 function_to_call()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 warning 22 } 23 exiting_thread_func(void * unused)24void *exiting_thread_func(void *unused) { 25 function_to_call(); // Break here and cause the thread to exit 26 return NULL; 27 } 28 main()29int main() { 30 char *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" case 38 // that we don't run past our breakpoint. 39 return ret_val; // Break here to make sure the thread exited. 40 } 41