From owner-freebsd-hackers@FreeBSD.ORG Tue Apr 21 13:23:28 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1F9DB138 for ; Tue, 21 Apr 2015 13:23:28 +0000 (UTC) Received: from mail-oi0-x22d.google.com (mail-oi0-x22d.google.com [IPv6:2607:f8b0:4003:c06::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D8F20170D for ; Tue, 21 Apr 2015 13:23:27 +0000 (UTC) Received: by oica37 with SMTP id a37so149935851oic.0 for ; Tue, 21 Apr 2015 06:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=vrUpBR6KB12Ob+HxM6IsYrxuLdwFbPX+6Zz3OvYmoeI=; b=tCfjgZkfD7VMr2QeJOwBDvvJOlUMBEBE2eV3ashul56EjP6DwHinOn/Z/E5x+PI4me n5oCYKpTgAEEOj5ARjfYsKaCQwkRb5uGON6XtiKXR/zjKm0+2o1xLLMVdR4JEOni3ylD kdhK6raBDaFdPgqC6mCvjtxx8BEJ+7xpWGwQtSMpIqbhy7f/N3EaA2yqFDScJ0EYVWHX ZY9lwfMchKtRtLfxUs7WEB0zQXv6EtWIh5GpoJhEOPDAHz2vRF1vjbp2enkKs0P9wzWF jjnsidBN8rd+eIOtgmWR5MXXh3s4WfOTNd8M/CW9LyU9BRLmuQfYxxurjf2ybxFc5zE5 rTRg== MIME-Version: 1.0 X-Received: by 10.60.157.41 with SMTP id wj9mr19099455oeb.16.1429622607139; Tue, 21 Apr 2015 06:23:27 -0700 (PDT) Received: by 10.60.24.10 with HTTP; Tue, 21 Apr 2015 06:23:27 -0700 (PDT) In-Reply-To: <20150421113914.GA6312@dft-labs.eu> References: <20150421113914.GA6312@dft-labs.eu> Date: Tue, 21 Apr 2015 18:53:27 +0530 Message-ID: Subject: Re: Clarification: Acquiring a mutex when a read/write lock is held From: Dheeraj Kandula To: Mateusz Guzik , Dheeraj Kandula , freebsd-hackers@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Apr 2015 13:23:28 -0000 Thanks for the response. I want to acquire the read/write lock first either as reader or writer and then acquire the mutex lock. I think the second part of your response deals with ordering of locks to prevent deadlock. That shouldn't be an issue. Thanks again for the quick reply. On Tue, Apr 21, 2015 at 5:09 PM, Mateusz Guzik wrote: > On Tue, Apr 21, 2015 at 04:33:24PM +0530, Dheeraj Kandula wrote: > > Hey All, > > Can you clarify the following > > > > I have a read write lock locked. Next I want to acquire a mutex when the > > read write lock is held. Is this allowed or not. As far as I can > understand > > from the "FreeBSD Kernel Developers Handbook" this operation is allowed > in > > FreeBSD9.0, 10.0 and further. > > > > But the read write lock cannot be held while sleeping. Doesn't this > > contradict the above statement, as a thread will go to sleep if can't > > acquire the mutex when another thread holds the mutex. > > > > Hence what sleep are we referring here. Is this sleep(unbounded sleep) or > > the bounded sleep. > > > > Both lock types allow bound sleep, so there is nothing preventing you > from establishing the order either way. > > Of course then there is the quesiton whether these particular locks you > have in mind can be taken in the order you want to take them. > > -- > Mateusz Guzik >