Date: Mon, 30 Sep 2013 07:24:06 -0700 From: Matthew Fleming <mdf@FreeBSD.org> To: Hooman Fazaeli <hoomanfazaeli@gmail.com> Cc: FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Re: rwlock(9) upgrade Message-ID: <CAMBSHm8h5LZN49WBwmMhFn-wfs21seZMVf2SgPkWjwdWAYr3sw@mail.gmail.com> In-Reply-To: <5249158D.5010101@gmail.com> References: <5249158D.5010101@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Sep 29, 2013 at 11:09 PM, Hooman Fazaeli <hoomanfazaeli@gmail.com>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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAMBSHm8h5LZN49WBwmMhFn-wfs21seZMVf2SgPkWjwdWAYr3sw>