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