tech-kern archive

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

Re: How to destroy a condvar(9) with waiters?



On December 29, 2015 3:41:39 AM CST, Stephan <stephanwib%googlemail.com@localhost> wrote:
>I think I found another approach. The destruction is now split in two
>parts:
>
>1) The destroyer changes the state to destroyed and removes the object
>from the global list.
>2) Each waiter checks the state and waiters count of the object. If
>the state is "destroyed" and the waiters count equals zero, a
>"delete_physical()" function is called which destroys the CVs,
>releases and destroys the interlock and finally frees all memory.
>
>The waiters part looks like this:
>
>port->kp_waiters++;
>error = cv_timedwait_sig(&port->kp_rdcv, &port->kp_interlock, t);
>port->kp_waiters--;
>if ((port->kp_state == kp_deleted) && (port->waiters == 0)) { /* port
>has been logically destroyed, and we are the last waiter */
>  kport_delete_physical(port);
>  return ENOENT;
>}
>
>Can this work?

The destroyer would need the same logic to handle the case where there are no waiters.  It looks like it would work either way, but it feels somehow cleaner to have the delete happen in the destroyer.

Eric




Home | Main Index | Thread Index | Old Index