Sometimes I noticed a panic in Rust to prevent a dead end. For example, this code is panicky:
let rw_lock = RwLock::new(42);
{
let data0 = rw_lock.write().unwrap();
let data1 = rw_lock.read().unwrap();
let data2 = rw_lock.read().unwrap();
}
However, this does not happen (instead, it causes a dead end):
let rw_lock = RwLock::new(42);
{
let data1 = rw_lock.read().unwrap();
let data2 = rw_lock.read().unwrap();
let data3 = rw_lock.write().unwrap();
}
When does a rusty panic arise, not a dead end? And why?
source
share