Branch: Tag:

2001-10-22

2001-10-22 23:54:47 by Martin Stjernholm <mast@lysator.liu.se>

Fixed bugs where the _disable_threads lock could fail to hold the
threads if there are threads dependent on uid or similar running when
the _disable_threads lock is requested. This bug could cause numerous
"Cannot wait for mutexes/conditions when threads are disabled"
backtraces when _disable_threads is used (e.g. through the Privs class
in Roxen). Cf [bug 1173 (#1173)].

Rev: src/modules/Java/jvm.c:1.18
Rev: src/threads.c:1.120
Rev: src/threads.h:1.81

1:   #include "global.h" - RCSID("$Id: threads.c,v 1.119 2000/11/06 17:05:00 grubba Exp $"); + RCSID("$Id: threads.c,v 1.120 2001/10/22 23:54:43 mast Exp $");      int num_threads = 1;   int threads_disabled = 0;
555:    JMP_BUF back;    INT32 tmp;    -  THREADS_FPRINTF(0, (stderr,"THREADS_DISALLOW() Thread %08x created...\n", +  THREADS_FPRINTF(0, (stderr,"new_thread_func(): Thread %08x created...\n",    (unsigned int)arg.id));       if((tmp=mt_lock( & interpreter_lock)))
566:    errno   #endif    ); +  +  while (threads_disabled) { +  THREADS_FPRINTF(1, (stderr, +  "new_thread_func(): Threads disabled\n")); +  co_wait(&threads_disabled_change, &interpreter_lock); +  } +     init_interpreter();    thread_id=arg.id;    stack_top=((char *)&data)+ (thread_stack_size-16384) * STACK_DIRECTION;
804:    {    THREADS_FPRINTF(1, (stderr,"WAITING TO LOCK m:%08x\n",(unsigned int)m));    co_wait(& m->condition, & interpreter_lock); +  while (threads_disabled) { +  THREADS_FPRINTF(1, (stderr, +  "f_mutex_lock(): Threads disabled\n")); +  co_wait(&threads_disabled_change, &interpreter_lock); +  }    }while(m->key);    SWAP_IN_CURRENT_THREAD();    }
972:    co_wait(c, &interpreter_lock);       /* Lock mutex */ -  while(mut->key) +  while(mut->key) {    co_wait(& mut->condition, &interpreter_lock); -  +  while (threads_disabled) { +  THREADS_FPRINTF(1, (stderr, +  "f_cond_wait(): Threads disabled\n")); +  co_wait(&threads_disabled_change, &interpreter_lock); +  } +  }    mut->key=key;    OB2KEY(key)->mut=mut;   
985:       SWAP_OUT_CURRENT_THREAD();    co_wait(c, &interpreter_lock); +  while (threads_disabled) { +  THREADS_FPRINTF(1, (stderr, +  "f_cond_wait(): Threads disabled\n")); +  co_wait(&threads_disabled_change, &interpreter_lock); +  }    SWAP_IN_CURRENT_THREAD();       pop_n_elems(args);
1039:       SWAP_OUT_CURRENT_THREAD();    -  while(th->status != THREAD_EXITED) +  while(th->status != THREAD_EXITED) {    co_wait(&th->status_change, &interpreter_lock); -  +  while (threads_disabled) { +  THREADS_FPRINTF(1, (stderr, +  "f_thread_id_result(): Threads disabled\n")); +  co_wait(&threads_disabled_change, &interpreter_lock); +  } +  }       SWAP_IN_CURRENT_THREAD();   
1234:    us_cookie = usinit("");   #endif /* SGI_SPROC_THREADS */    -  THREADS_FPRINTF(0, (stderr, "THREADS_DISALLOW() Initializing threads.\n")); +  THREADS_FPRINTF(0, (stderr, "low_th_init() Initializing threads.\n"));      #ifdef POSIX_THREADS   #ifdef HAVE_PTHREAD_INIT