manoj 99/04/29 12:34:23
Modified: . STATUS pthreads/src/main http_accept.c http_main.c Log: Get rid of thread_starter_thread, and just start all of our worker threads from child_main. This makes the code simpler, and eliminates any race conditions involving trying to shutdown a child process while still starting threads. Revision Changes Path 1.23 +1 -9 apache-apr/STATUS Index: STATUS =================================================================== RCS file: /home/cvs/apache-apr/STATUS,v retrieving revision 1.22 retrieving revision 1.23 diff -u -u -r1.22 -r1.23 --- STATUS 1999/04/27 06:23:04 1.22 +++ STATUS 1999/04/29 19:34:19 1.23 @@ -1,5 +1,5 @@ Apache Portable Runtime STATUS: -Last modified at [$Date: 1999/04/27 06:23:04 $] +Last modified at [$Date: 1999/04/29 19:34:19 $] Release: @@ -42,14 +42,6 @@ Everything Needs patch: - - On Red Hat 5.2, with a very low MaxRequestsPerChild (e.g. 10), when the - server is banged on with ApacheBench, occasionally, the main thread of a - process hangs around in pthread_exit_process. The size of that process is - always around 11M. This bug is also exhibited by sending lots of SIGHUPs - to the parent process rapidly (but not SIGWINCHes). The suspicion is that - this is either an error in how pthread calls are used in the server, or a - libc bug (the last refuge of a desperate programer). When the server runs at a high load, and the load later drops off, the server tries to kill off some children. The problem is that the 1.11 +1 -12 apache-apr/pthreads/src/main/http_accept.c Index: http_accept.c =================================================================== RCS file: /home/cvs/apache-apr/pthreads/src/main/http_accept.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -u -r1.10 -r1.11 --- http_accept.c 1999/04/22 05:46:53 1.10 +++ http_accept.c 1999/04/29 19:34:20 1.11 @@ -245,7 +245,7 @@ */ int i = ap_threads_per_child; if (lr) { - while (lr->next != NULL) { + while (lr != NULL) { (void) ap_update_child_status(my_child_num, i, SERVER_STARTING, (request_rec *) NULL); @@ -277,17 +277,6 @@ /* no listening sockets???? Kill the server please. */ exit(0); } - (void) ap_update_child_status(my_child_num, i, SERVER_STARTING, - (request_rec *) NULL); - - my_info = NULL; - - my_info = (proc_info *) malloc(sizeof(proc_info)); - my_info->pid = my_child_num; - my_info->tid = i; - my_info->sd = lr->fd; - - accept_thread(my_info); } int get_connection(struct sockaddr *sa_client) 1.78 +31 -52 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.77 retrieving revision 1.78 diff -u -u -r1.77 -r1.78 --- http_main.c 1999/04/22 04:14:40 1.77 +++ http_main.c 1999/04/29 19:34:21 1.78 @@ -1884,61 +1884,16 @@ #endif /* ndef WIN32 */ } -static void *thread_starter_thread(void *thread_arg) { - int i; - pthread_t thread; - int my_child_num = *((int *) thread_arg); - proc_info *my_info = NULL; - - /* Setup worker threads */ - for (i=0; i < ap_threads_per_child; i++) { - - my_info = NULL; - - my_info = (proc_info *)malloc(sizeof(proc_info)); - my_info->pid = my_child_num; - my_info->tid = i; - my_info->sd = 0; - - /* We are creating threads right now */ - (void) ap_update_child_status(my_child_num, i, SERVER_STARTING, - (request_rec *) NULL); - if (pthread_create(&thread, NULL, worker_thread, my_info)) { - ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, - "pthread_create: unable to create worker thread"); - /* - * We failed to create a thread. Update the scoreboard, - * or it will say SERVER_STARTING forever. - */ - (void) ap_update_child_status(my_child_num, i, SERVER_DEAD, - (request_rec *) NULL); - exit(1); /* We won't always exit here, but for no this is okay */ - } - - /* We let each thread update it's own scoreboard entry. This is done - * because it let's us deal with tid better. - */ - } - - - /* Begin accepting requests - * Design: - * - */ - start_accepting_connections(my_child_num); - return NULL; -} - static void child_main(int child_num_arg) { sigset_t sig_mask; int signal_received; pthread_t thread; - int j; + int i, j; + int my_child_num = child_num_arg; + proc_info *my_info = NULL; my_pid = getpid(); - - pchild = ap_make_sub_pool(pconf); /*stuff to do before we switch id's, so we have permissions.*/ @@ -1965,13 +1920,37 @@ ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, "pthread_sigmask"); } + /* Setup worker threads */ + for (i=0; i < ap_threads_per_child; i++) { + my_info = NULL; + + my_info = (proc_info *)malloc(sizeof(proc_info)); + my_info->pid = my_child_num; + my_info->tid = i; + my_info->sd = 0; + + /* We are creating threads right now */ + (void) ap_update_child_status(my_child_num, i, SERVER_STARTING, + (request_rec *) NULL); + if (pthread_create(&thread, NULL, worker_thread, my_info)) { + ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, + "pthread_create: unable to create worker thread"); + /* + * We failed to create a thread. Update the scoreboard, + * or it will say SERVER_STARTING forever. + */ + (void) ap_update_child_status(my_child_num, i, SERVER_DEAD, + (request_rec *) NULL); + exit(1); /* We won't always exit here, but for no this is okay */ + } - if (pthread_create(&thread, NULL, thread_starter_thread, &child_num_arg)) { - ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, - "pthread_create: unable to create thread starter thread"); - clean_child_exit(1); + /* We let each thread update it's own scoreboard entry. This is done + * because it let's us deal with tid better. + */ } + + start_accepting_connections(my_child_num); /* This thread will be the one responsible for handling signals */ sigemptyset(&sig_mask);