[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-hackers
Subject:    Re: rwlock(9) upgrade
From:       Matthew Fleming <mdf () FreeBSD ! org>
Date:       2013-09-30 14:24:06
Message-ID: CAMBSHm8h5LZN49WBwmMhFn-wfs21seZMVf2SgPkWjwdWAYr3sw () mail ! gmail ! com
[Download RAW message or body]

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
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic