You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pub fn try_upgradeable_read(&self) -> Option<RwLockUpgradableGuard<T, R>> {
if self.lock.fetch_or(UPGRADED, Ordering::Acquire) & (WRITER | UPGRADED) == 0 {
Some(RwLockUpgradableGuard {
phantom: PhantomData,
inner: self,
data: unsafe { &*self.data.get() },
})
} else {
// We can't unflip the UPGRADED bit back just yet as there is another upgradeable or write lock.
// When they unlock, they will clear the bit.
None
}
}
RwLockUpgradableGuard::try_upgrade_internal() contains compare_exchange( &inner.lock, UPGRADED, WRITER, Ordering::Acquire, Ordering::Relaxed,strong ) which clears UPGRADED and sets WRITER.
If try_upgrade_internal() is called then UPGRADED is cleared and WRITER is set. If try_upgradeable_read() is called on another thread this will set UPGRADED and return None, as it mentions in the fail branch it cant clear UPGRADED and the owner of the lock must clear it. However a number of debug assertions particularly in RwLockWriteGuard::downgrade_to_upgradeable and RwLockUpgradableGuard::drop() will panic in this event, even though RwLockWriteGuard::downgrade_to_upgradeable clears both UPGRADED and WRITER
The text was updated successfully, but these errors were encountered:
RwLock::try_upgradeable_read()
isRwLockUpgradableGuard::try_upgrade_internal()
containscompare_exchange( &inner.lock, UPGRADED, WRITER, Ordering::Acquire, Ordering::Relaxed,strong )
which clearsUPGRADED
and setsWRITER
.If
try_upgrade_internal()
is called thenUPGRADED
is cleared andWRITER
is set. Iftry_upgradeable_read()
is called on another thread this will setUPGRADED
and returnNone
, as it mentions in the fail branch it cant clearUPGRADED
and the owner of the lock must clear it. However a number of debug assertions particularly inRwLockWriteGuard::downgrade_to_upgradeable
andRwLockUpgradableGuard::drop()
will panic in this event, even thoughRwLockWriteGuard::downgrade_to_upgradeable
clears bothUPGRADED
andWRITER
The text was updated successfully, but these errors were encountered: