From owner-freebsd-hackers@FreeBSD.ORG Mon Sep 30 14:24:07 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 97A94114 for ; Mon, 30 Sep 2013 14:24:07 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-qa0-x231.google.com (mail-qa0-x231.google.com [IPv6:2607:f8b0:400d:c00::231]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 595D12B74 for ; Mon, 30 Sep 2013 14:24:07 +0000 (UTC) Received: by mail-qa0-f49.google.com with SMTP id k15so2323190qaq.8 for ; Mon, 30 Sep 2013 07:24:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=Qkjrz3utAYRNQFEPDHtL6H365A19RFLexBAgPKoiGGE=; b=eYt2qmVI7va7U8dx/rdoziIT4iGlTDJx56/Zgvqv/QYIaCzGD+eOnFTJ/a9AZ4Ob85 gDQOb2TJK5pDbnI7YQmEzdKMDyw6sRO5YeJm8vO/D3O+gVbtit52dsh2iFAVZiZdUie0 Q2nYSfQTjsEmXUdEDzxNGJ89l9LYZRfnn8Nb3KdmYNN9BIDfQL7trwAV5VmIy8YXhFYg vmzrOJdF4yDgWfTkeOYqzxUBsHzyFPc/QB6Sf/Kk0WdR1ETH3oGhX/CX4JrMJsZaMOQx wXNSAPoxlkZgpNj6LtUHuS4ibrx/28tzLi0UoJmypKg41Tm6M8PQI0fiZAGnVqQOmGjq pt0Q== MIME-Version: 1.0 X-Received: by 10.229.109.193 with SMTP id k1mr28736486qcp.9.1380551046326; Mon, 30 Sep 2013 07:24:06 -0700 (PDT) Sender: mdf356@gmail.com Received: by 10.229.225.129 with HTTP; Mon, 30 Sep 2013 07:24:06 -0700 (PDT) In-Reply-To: <5249158D.5010101@gmail.com> References: <5249158D.5010101@gmail.com> Date: Mon, 30 Sep 2013 07:24:06 -0700 X-Google-Sender-Auth: xirdXjNk1A-igweQNB9b3laqE8o Message-ID: Subject: Re: rwlock(9) upgrade From: Matthew Fleming To: Hooman Fazaeli Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Sep 2013 14:24:07 -0000 On Sun, Sep 29, 2013 at 11:09 PM, Hooman Fazaeli wrote: > Hi, > > For rwlock(9), there is no rwlock_upgrade function. > Is it safe to use rw_wlock() for that purpose? In other words, Does calling > rw_wlock() upgradeanalready r-locked lock? No, calling rw_wlock when you hold the lock in read mode will deadlock. lockmgr(9) supports LK_UPGRADE, but note (see the recent commit for LK_TRYUPGRADE) that LK_UPGRADE, if it cannot do the upgrade immediately, e.g. due to multiple shared lockers, will unlock and wait to finish the upgrade. In general, the idea is that upgrade is not a good operation, since there's no way to know ahead of time if it can be done without a lock release. So code is better off explicitly unlocking the shared/read-mode lock and explicitly blocking for an exclusive/write lock. Thanks, matthew