diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-02-27 21:56:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-27 21:56:24 +0100 |
| commit | e38b3eb0b56c7314980649d35b21b61e74a41bdc (patch) | |
| tree | 9ba99a7fb03b2430b974c862d28192f57d476ece /compiler/rustc_llvm/llvm-wrapper | |
| parent | a70be0bec92d59674348b22790b1b3681415d4e3 (diff) | |
| parent | 261c952ba66f130096edf530fae50bd0640e09e4 (diff) | |
| download | rust-e38b3eb0b56c7314980649d35b21b61e74a41bdc.tar.gz rust-e38b3eb0b56c7314980649d35b21b61e74a41bdc.zip | |
Rollup merge of #82596 - matklad:rwlock, r=sfackler
clarify RW lock's priority gotcha
In particular, the following program works on Linux, but deadlocks on
mac:
```rust
use std::{
sync::{Arc, RwLock},
thread,
time::Duration,
};
fn main() {
let lock = Arc::new(RwLock::new(()));
let r1 = thread::spawn({
let lock = Arc::clone(&lock);
move || {
let _rg = lock.read();
eprintln!("r1/1");
sleep(1000);
let _rg = lock.read();
eprintln!("r1/2");
sleep(5000);
}
});
sleep(100);
let w = thread::spawn({
let lock = Arc::clone(&lock);
move || {
let _wg = lock.write();
eprintln!("w");
}
});
sleep(100);
let r2 = thread::spawn({
let lock = Arc::clone(&lock);
move || {
let _rg = lock.read();
eprintln!("r2");
sleep(2000);
}
});
r1.join().unwrap();
r2.join().unwrap();
w.join().unwrap();
}
fn sleep(ms: u64) {
std::thread::sleep(Duration::from_millis(ms))
}
```
Context: I was completely mystified by a my CI deadlocking on mac ([here](https://github.com/matklad/xshell/pull/7)), until ``@azdavis`` debugged the issue. See a stand-alone reproduciton here: https://github.com/matklad/xshell/pull/15
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper')
0 files changed, 0 insertions, 0 deletions
