Upgrade RwLockReadLock

Hi, I have a RwLock that I lock with .read(). After inspection, I might want to update the content.
Is there any way to upgrade the guard from read to write, similar to Weak::upgrade? Or is releasing and re-locking the best option?

You should just release and re-lock it.

Unlike the situation with downgrading a write lock, its impossible to implement an upgrade that does something different than unlock+re-lock.

1 Like

Sure, this makes sense.

It is possible to take the lock in a special "upgradeable read" mode which can be atomically upgraded to a write lock without deadlocking, but it cannot be held concurrently with other upgradeable readers. The standard library's RwLock does not support this mode, but e.g. parking_lot does: RwLock in lock_api - Rust.

1 Like