Branch: Tag:

2017-08-07

2017-08-07 15:51:58 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Threads: Check threads_disabled state after co_wait_interpreter().

Some other thread may disable threads while we're waiting in
co_wait_interpreter(), in which case we must wait for them
to be enabled again before proceeding.

Potential fix for PIKE-18 (#8018).

2055:    thread_state));    while (thread_state->status == THREAD_NOT_STARTED)    low_co_wait_interpreter (&thread_state->status_change); +  if (threads_disabled) { +  /* Some other thread disabled threads while we were waiting for +  * the cond var. Wait for the threads disabled lock to be released. +  */ +  threads_disabled_wait(DLOC); +  }    THREADS_FPRINTF(0, (stderr, "f_thread_create %p continue\n", thread_state));    SWAP_IN_CURRENT_THREAD();    } else {
2326:    SWAP_IN_CURRENT_THREAD();    check_threads_etc();    }while(m->key); +  if (threads_disabled) { +  /* Some other thread disabled threads while we were waiting for +  * the mutex. Wait for the threads disabled lock to be released. +  */ +  SWAP_OUT_CURRENT_THREAD(); +  threads_disabled_wait(DLOC); +  SWAP_IN_CURRENT_THREAD(); +  check_threads_etc(); +  }    m->num_waiting--;    }   
2786:    SWAP_IN_CURRENT_THREAD();    check_threads_etc();    } +  if (threads_disabled) { +  /* Some other thread disabled threads while we were waiting for the mutex +  * or the cond var. Wait for the threads disabled lock to be released. +  */ +  SWAP_OUT_CURRENT_THREAD(); +  threads_disabled_wait(DLOC); +  SWAP_IN_CURRENT_THREAD(); +  check_threads_etc(); +  }    mut->key=key;    OB2KEY(key)->mut=mut;    OB2KEY(key)->mutex_obj = mutex_obj;
2971:    while(th->status < THREAD_EXITED) {    SWAP_OUT_CURRENT_THREAD();    co_wait_interpreter(&th->status_change); +  if (threads_disabled) { +  /* Some other thread disabled threads while we were waiting for +  * the cond var. Wait for the threads disabled lock to be released. +  */ +  threads_disabled_wait(DLOC); +  }    SWAP_IN_CURRENT_THREAD();    check_threads_etc();    THREADS_FPRINTF(0,