tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

How to destroy a condvar(9) with waiters?



Hi folks,

given there is an object with the following

-an interlock (mutex)
-a condvar(9)
-a "state" variable which can be set to something like state_deleted

and there are waiters on that condvar in cv_timedwait_sig(). The
waiters do the following

error = cv_timedwait_sig(&port->kp_rdcv, &port->kp_interlock, (mstohz(timeout));
if (error || (port->kp_state == kp_deleted)) {
  error = (error == EWOULDBLOCK) ? ETIMEDOUT : ENOENT;
  mutex_exit(&port->kp_interlock);
  return error;
}

How can I safely destroy the condvar and interlock mutex? I would propose to

-aquire the interlock
-set the state to (in this case) kp_deleted
-cv_broadcast the condvar
-release the interlock

If I reaquire the interlock now, can I be sure that all waiters are
gone at this point? I would then proceed like this

-reaquire the interlock
-destroy the condvar
-delete the object from the global list (nobody can find it afterwards)
-release the interlock
-destroy the interlock


Thanks and regards,

Stephan


Home | Main Index | Thread Index | Old Index