manoj 99/02/16 21:32:02
Modified: pthreads/src/main http_main.c Log: pthread calls while handling a signal are baaaaad voodoo. This is another way to allow cleanups to run after all threads exit. Revision Changes Path 1.37 +11 -10 apache-apr/pthreads/src/main/http_main.c Index: http_main.c =================================================================== RCS file: /home/cvs/apache-apr/pthreads/src/main/http_main.c,v retrieving revision 1.36 retrieving revision 1.37 diff -u -u -r1.36 -r1.37 --- http_main.c 1999/02/17 00:03:41 1.36 +++ http_main.c 1999/02/17 05:32:00 1.37 @@ -431,13 +431,6 @@ ap_pclosesocket(pconf, lr->fd); lr= lr->next; } - - for (i = 0; i < ss->worker_threads + ss->acceptor_threads; i++) { - if (ap_scoreboard_image->servers[index][i].status != SERVER_DEAD) { - pthread_join(ap_scoreboard_image->servers[index][i].tid, NULL); - } - } - clean_child_exit(0); } /****** ZZZ this should probably be abstracted to it's own file. ****/ @@ -2300,7 +2293,7 @@ } ap_update_child_status(my_pid, my_tid, SERVER_DEAD, (request_rec *) NULL); pthread_once(&firstcall, graceful_killer); - pthread_exit(NULL); + return NULL; } void * worker_thread(void * dummy) @@ -2328,8 +2321,7 @@ ap_destroy_pool(ptrans); ap_update_child_status(my_pid, my_tid, SERVER_DEAD, (request_rec *) NULL); pthread_once(&firstcall, graceful_killer); - - pthread_exit(NULL); + return NULL; } /***************************************************************** @@ -2573,6 +2565,15 @@ lr->used = 1; accept_thread(my_info); + + /* Wait for other threads to die, then clean up. Note: joining oneself is + * a bad thing, so we make sure that i < my_info->tid, not <= */ + for (i = 0; i < my_info->tid; i++) { + if (ap_scoreboard_image->servers[my_child_num][i].status != SERVER_DEAD) { + pthread_join(ap_scoreboard_image->servers[my_child_num][i].tid, NULL); + } + } + clean_child_exit(0); } static int make_child(server_rec *s, int slot, time_t now) /* ZZZ */