cahirwpz/mimiker

Potential lost wakeup in condition variables

Closed this issue · 0 comments

cv_wait and cv_wait_timed are supposed to atomically release a lock and go to sleep:

void cv_wait(condvar_t *cv, cv_lock_t m) {
WITH_NO_PREEMPTION {
cv->waiters++;
mutex_unlock(m);
sleepq_wait(cv, __caller(0));
}
mutex_lock(m, __caller(0));
}

Preemption is disabled between unlocking and going to sleep, but we might get an interrupt. Some interrupt filter routines call cv_signal (e.g. atkbdc_intr), so there is a potential lost wakeup.
One solution would be to use WITH_INTR_DISABLED instead of WITH_NO_PREEMPTION.