1 /* Test that all threads are killed when exit() is called. */ 2 3 #include <pthread.h> 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include <unistd.h> 7 thread_proc(void * arg)8void *thread_proc(void *arg) 9 { 10 /* Wait for main thread to block. */ 11 sleep(2); 12 13 /* Exit the program. */ 14 exit(0); 15 16 return NULL; 17 } 18 main(void)19int main(void) 20 { 21 pthread_t thread; 22 void *status; 23 24 if (pthread_create(&thread, NULL, thread_proc, NULL)) { 25 perror("pthread_create"); 26 return 1; 27 } 28 29 if (pthread_join(thread, &status)) { 30 perror("pthread_join"); 31 return 1; 32 } 33 34 /* This code should not be reached. */ 35 fprintf(stderr, "Thread joined\n"); 36 37 return 0; 38 } 39 40