From owner-freebsd-hackers@FreeBSD.ORG Wed May 2 09:08:02 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0AFDA16A403 for ; Wed, 2 May 2007 09:08:02 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.227]) by mx1.freebsd.org (Postfix) with ESMTP id BB8B413C483 for ; Wed, 2 May 2007 09:08:01 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: by wx-out-0506.google.com with SMTP id s18so56189wxc for ; Wed, 02 May 2007 02:08:01 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:reply-to:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=nY9gFwUQ6Vg4Swx3kVPXDJTFRUP/gTaDu5XSOzqm6/nCB2GgRVNLeR+miRE6O5c8eYp4RGS50ZT/1Xh5OmUGhKdxJZsA6ZE5Vz2iAszURGIccgkJlWeQjVd2mg6WN5K+Ahqj1bIstOHY3iQcj/iARr141inwBWYUcagf/gWN0CE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:reply-to:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=ZEV8zeNFrMRUEKPDVLG6Qx/+hyxtqTqYw28DsSzkdkp8f3wSvdDMWhuKFfMJzuFtunLR0egYzNRLf8CtimktBGwpUd01NG8mTBv56AaYhF40IbQA9mzjz/Fa8BYHC4grr6JzrZcB34R4lquwpclxSe9uGS28h2dt7pKlKgemcGo= Received: by 10.82.189.6 with SMTP id m6mr964004buf.1178096879960; Wed, 02 May 2007 02:07:59 -0700 (PDT) Received: from ?172.31.5.21? ( [89.97.252.178]) by mx.google.com with ESMTP id y34sm71571iky.2007.05.02.02.07.48; Wed, 02 May 2007 02:07:56 -0700 (PDT) Message-ID: <4638C639.7060407@FreeBSD.org> Date: Wed, 02 May 2007 19:11:21 +0200 From: Attilio Rao User-Agent: Thunderbird 1.5 (X11/20060526) MIME-Version: 1.0 To: babkin@users.sf.net References: <2782784.9021177711758431.JavaMail.root@vms073.mailsrvcs.net> In-Reply-To: <2782784.9021177711758431.JavaMail.root@vms073.mailsrvcs.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: Attilio Rao Cc: freebsd-hackers@freebsd.org, Julian Elischer , Hans Petter Selasky Subject: Re: msleep() on recursivly locked mutexes X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: attilio@FreeBSD.org List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 May 2007 09:08:02 -0000 Sergey Babkin wrote: >> From: Julian Elischer >> Basically you shouldn't have a recursed mutex FULL STOP. We have a couple >> of instances in the kernel where we allow a mutex to recurse, but they had to be >> hard fought, and the general rule is "Don't". If you are recursing on >> a mutex you need to switch to some other method of doing things. >> e.g. reference counts, turnstiles, whatever.. use the mutex to create these > > One typical problem is when someone holds a mutex > and needs to call a function that also tried to get the mutex. > The typical solution for it is to provide two versions of > this function, one expecting the mutex being already held > by the caller, the other being a wrapper that grabs the mutex and > then calls the actual worker function. If that happens rather frequently, the better thing to do is assuming that the lock is alredy held in the function (adding an assertion for it) than acquiring/releasing before/after the function. Attilio