From owner-freebsd-hackers@FreeBSD.ORG Thu Aug 10 15:35:50 2006 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id F404416A4DD for ; Thu, 10 Aug 2006 15:35:49 +0000 (UTC) (envelope-from xdivac02@stud.fit.vutbr.cz) Received: from eva.fit.vutbr.cz (eva.fit.vutbr.cz [147.229.10.14]) by mx1.FreeBSD.org (Postfix) with ESMTP id 57EE043D49 for ; Thu, 10 Aug 2006 15:35:48 +0000 (GMT) (envelope-from xdivac02@stud.fit.vutbr.cz) Received: from eva.fit.vutbr.cz (localhost [127.0.0.1]) by eva.fit.vutbr.cz (envelope-from xdivac02@eva.fit.vutbr.cz) (8.13.7/8.13.7) with ESMTP id k7AFZhav019151 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO); Thu, 10 Aug 2006 17:35:43 +0200 (CEST) Received: (from xdivac02@localhost) by eva.fit.vutbr.cz (8.13.7/8.13.3/Submit) id k7AFZhnC019150; Thu, 10 Aug 2006 17:35:43 +0200 (CEST) Date: Thu, 10 Aug 2006 17:35:43 +0200 From: Divacky Roman To: Brooks Davis Message-ID: <20060810153543.GA19047@stud.fit.vutbr.cz> References: <20060810151616.GA17109@stud.fit.vutbr.cz> <20060810152359.GA21318@lor.one-eyed-alien.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060810152359.GA21318@lor.one-eyed-alien.net> User-Agent: Mutt/1.4.2i X-Scanned-By: MIMEDefang 2.54 on 147.229.10.14 Cc: hackers@freebsd.org Subject: Re: SoC: help with LISTs and killing procs X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Aug 2006 15:35:50 -0000 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