Branch: Tag:

2001-10-22

2001-10-22 23:52:56 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.36
Rev: src/signal_handler.c:1.193
Rev: src/threads.c:1.159
Rev: src/threads.h:1.113

1:   #include "global.h" - RCSID("$Id: threads.c,v 1.158 2001/09/25 14:05:09 grubba Exp $"); + RCSID("$Id: threads.c,v 1.159 2001/10/22 23:52:54 mast Exp $");      PMOD_EXPORT int num_threads = 1;   PMOD_EXPORT int threads_disabled = 0;
578:    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));      #ifdef HAVE_BROKEN_LINUX_THREAD_EUID
599:    errno   #endif    ); +  +  while (threads_disabled) { +  THREADS_FPRINTF(1, (stderr, +  "new_thread_func(): Threads disabled\n")); +  co_wait_interpreter(&threads_disabled_change); +  } +     SWAP_IN_THREAD(OBJ2THREAD(arg.id)); /* Init struct */    init_interpreter();    Pike_interpreter.thread_id=arg.id;
838:    {    THREADS_FPRINTF(1, (stderr,"WAITING TO LOCK m:%08x\n",(unsigned int)m));    co_wait_interpreter(& m->condition); +  while (threads_disabled) { +  THREADS_FPRINTF(1, (stderr, +  "f_mutex_lock(): Threads disabled\n")); +  co_wait_interpreter(&threads_disabled_change); +  }    }while(m->key);    SWAP_IN_CURRENT_THREAD();    }
1004:    /* Wait and allow mutex operations */    SWAP_OUT_CURRENT_THREAD();    co_wait_interpreter(c); +  while (threads_disabled) { +  THREADS_FPRINTF(1, (stderr, +  "f_cond_wait(): Threads disabled\n")); +  co_wait_interpreter(&threads_disabled_change); +  }       /* Lock mutex */ -  while(mut->key) +  while(mut->key) {    co_wait_interpreter(& mut->condition); -  +  while (threads_disabled) { +  THREADS_FPRINTF(1, (stderr, +  "f_cond_wait(): Threads disabled\n")); +  co_wait_interpreter(&threads_disabled_change); +  } +  }    mut->key=key;    OB2KEY(key)->mut=mut;   
1019:       SWAP_OUT_CURRENT_THREAD();    co_wait_interpreter(c); +  while (threads_disabled) { +  THREADS_FPRINTF(1, (stderr, +  "f_cond_wait(): Threads disabled\n")); +  co_wait_interpreter(&threads_disabled_change); +  }    SWAP_IN_CURRENT_THREAD();       pop_n_elems(args);
1078:       SWAP_OUT_CURRENT_THREAD();    -  while(th->status != THREAD_EXITED) +  while(th->status != THREAD_EXITED) {    co_wait_interpreter(&th->status_change); -  +  while (threads_disabled) { +  THREADS_FPRINTF(1, (stderr, +  "f_thread_id_result(): Threads disabled\n")); +  co_wait_interpreter(&threads_disabled_change); +  } +  }       SWAP_IN_CURRENT_THREAD();