rwlock(9) upgrade
Matthew Fleming
mdf at FreeBSD.org
Mon Sep 30 14:24:07 UTC 2013
On Sun, Sep 29, 2013 at 11:09 PM, Hooman Fazaeli <hoomanfazaeli at 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
More information about the freebsd-hackers
mailing list