httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject cvs commit: httpd-2.0/server/mpm/threaded threaded.c
Date Thu, 26 Jul 2001 18:11:53 GMT
trawick     01/07/26 11:11:53

  Modified:    .        CHANGES
               server/mpm/threaded threaded.c
  Log:
  Fix a segfault in threaded.c caused by passing uninitialized
  apr_thread_t * to apr_thread_join().  Now we clear the array
  of apr_thread_t * initially so we can track which threads we
  actually created.
  
  Other changes:
  
  don't clobber storage by passing bogus array entry as 1st
  parameter to apr_thread_create() to create the start_threads()
  thread
  
  join up with the start_threads() thread at termination so that
  it is cleaned up and so that no worker threads are still being
  created
  
  Revision  Changes    Path
  1.258     +3 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.257
  retrieving revision 1.258
  diff -u -r1.257 -r1.258
  --- CHANGES	2001/07/24 22:55:28	1.257
  +++ CHANGES	2001/07/26 18:11:53	1.258
  @@ -1,5 +1,8 @@
   Changes with Apache 2.0.22-dev
   
  +  *) Fix a segfault in threaded.c caused by passing uninitialized
  +     apr_thread_t * to apr_thread_join().  [Jeff Trawick]
  +
     *) Use new APR number conversion functions to reduce CPU consumption 
        when setting the content length, and in mod_log_config.
        [Brian Pane]
  
  
  
  1.50      +11 -4     httpd-2.0/server/mpm/threaded/threaded.c
  
  Index: threaded.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/mpm/threaded/threaded.c,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- threaded.c	2001/07/25 20:48:53	1.49
  +++ threaded.c	2001/07/26 18:11:53	1.50
  @@ -683,7 +683,7 @@
       apr_status_t rv;
       int threads_created = 0;
   
  -    while (1) {
  +    while (!workers_may_exit) { /* give up when the process is told to terminate */
           for (i=0; i < ap_threads_per_child; i++) {
               int status = ap_scoreboard_image->servers[child_num_arg][i].status;
   
  @@ -744,6 +744,7 @@
       apr_status_t rv;
       thread_starter *ts;
       apr_threadattr_t *thread_attr;
  +    apr_thread_t *start_thread_id;
   
       ap_my_pid = getpid();
       apr_pool_create(&pchild, pconf);
  @@ -793,7 +794,10 @@
   
       /* Setup worker threads */
   
  -    threads = (apr_thread_t **)malloc(sizeof(apr_thread_t *) * ap_threads_per_child);
  +    /* clear the storage; we may not create all our threads immediately, and we want
  +     * a 0 entry to indicate a thread which was not created
  +     */
  +    threads = (apr_thread_t **)calloc(1, sizeof(apr_thread_t *) * ap_threads_per_child);
       if (threads == NULL) {
           ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf,
                        "malloc: out of memory");
  @@ -814,7 +818,7 @@
       ts->child_num_arg = child_num_arg;
       ts->threadattr = thread_attr;
   
  -    if ((rv = apr_thread_create(&threads[i], thread_attr, start_threads, ts, pchild)))
{
  +    if ((rv = apr_thread_create(&start_thread_id, thread_attr, start_threads, ts, pchild)))
{
           ap_log_error(APLOG_MARK, APLOG_ALERT, rv, ap_server_conf,
                        "apr_thread_create: unable to create worker thread");
           /* In case system resources are maxxed out, we don't want
  @@ -835,8 +839,11 @@
        *   If the worker already exited, then the join frees their resources and returns.
        *   If the worker hasn't exited, then this blocks until they have (then cleans up).
        */
  +    apr_thread_join(&rv, start_thread_id);
       for (i = 0; i < ap_threads_per_child; i++) {
  -        apr_thread_join(&rv, threads[i]);
  +        if (threads[i]) { /* if we ever created this thread */
  +            apr_thread_join(&rv, threads[i]);
  +        }
       }
   
       free(threads);
  
  
  

Mime
View raw message