SoC: help with LISTs and killing procs
Divacky Roman
xdivac02 at stud.fit.vutbr.cz
Thu Aug 10 15:35:50 UTC 2006
On Thu, Aug 10, 2006 at 10:23:59AM -0500, Brooks Davis wrote:
> On Thu, Aug 10, 2006 at 05:16:17PM +0200, Divacky Roman wrote:
> > hi
> >
> > I am doing this:
> >
> > (pseudocode)
> > LIST_FOREACH_SAFE(em, &td_em->shared->threads, threads, tmp_em) {
> >
> > kill(em, SIGKILL);
> > }
> >
> > kill(SIGKILL) calls exit() which calls my exit_hook()
> >
> > my exit_hook() does LIST_REMOVE(em, threads).
> >
> > the problem is that this is not synchronous so I am getting a panic by INVARIANTS
> > that "Bad link elm prev->next != elm". This is because I list 1st item in the list
> > I call kill on it, then process 2nd list, then scheduler preempts my code and calls
> > exit() on the first proc which removes the first entry and bad things happen.
> >
> > I see this possible solutions:
> >
> > make this synchronous, it can be done by something like:
> >
> > ....
> > kill(em, SIGKILL);
> > wait_for_proc_to_vanish();
> >
> > pls. tell me what do you think about this solution and if its correct what is the wait_for_proc_to_vanish()
> >
> > maybe there's some better solution, pls tell me.
>
> It sounds like you need a lock protecting the list. If you held it over
> the whole loop you could signal all processes before the exit_hook could
> remove any.
I dont understand. I am protecting the lock by a rw_rlock();
the exit_hook() then acquires rw_wlock(); when removing the entry. what exactly do you
suggest me to do? I dont get it.
thnx for claryfication
roman
More information about the freebsd-hackers
mailing list