Skip to content

Commit

Permalink
Auto merge of #2267 - RalfJung:rustup, r=RalfJung
Browse files Browse the repository at this point in the history
rustup

I cannot reproduce rust-lang/rust#98493 so let's see what CI says.
  • Loading branch information
bors committed Jun 25, 2022
2 parents e3d42e6 + a74c17d commit 82b007e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 47 deletions.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a09c668c965f735f4cd59e7158662b9daa0b71ba
8aab472d52ba7314dc193c73abcd384e2586123c
49 changes: 3 additions & 46 deletions tests/pass/concurrency/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn check_conditional_variables_notify_one() {
let pair2 = pair.clone();

// Spawn a new thread.
thread::spawn(move || {
let t = thread::spawn(move || {
thread::yield_now();
let (lock, cvar) = &*pair2;
let mut started = lock.lock().unwrap();
Expand All @@ -50,6 +50,8 @@ fn check_conditional_variables_notify_one() {
while !*started {
started = cvar.wait(started).unwrap();
}

t.join().unwrap();
}

/// Test that waiting on a conditional variable with a timeout does not
Expand Down Expand Up @@ -191,51 +193,6 @@ fn check_once() {
}
}

fn check_rwlock_unlock_bug1() {
// There was a bug where when un-read-locking an rwlock that still has other
// readers waiting, we'd accidentally also let a writer in.
// That caused an ICE.
let l = Arc::new(RwLock::new(0));

let r1 = l.read().unwrap();
let r2 = l.read().unwrap();

// Make a waiting writer.
let l2 = l.clone();
thread::spawn(move || {
let mut w = l2.write().unwrap();
*w += 1;
});
thread::yield_now();

drop(r1);
assert_eq!(*r2, 0);
thread::yield_now();
thread::yield_now();
thread::yield_now();
assert_eq!(*r2, 0);
drop(r2);
}

fn check_rwlock_unlock_bug2() {
// There was a bug where when un-read-locking an rwlock by letting the last reader leaver,
// we'd forget to wake up a writer.
// That meant the writer thread could never run again.
let l = Arc::new(RwLock::new(0));

let r = l.read().unwrap();

// Make a waiting writer.
let l2 = l.clone();
let h = thread::spawn(move || {
let _w = l2.write().unwrap();
});
thread::yield_now();

drop(r);
h.join().unwrap();
}

fn park_timeout() {
let start = Instant::now();

Expand Down
47 changes: 47 additions & 0 deletions tests/pass/concurrency/sync_nopreempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,53 @@ fn check_conditional_variables_notify_all() {
}
}

fn check_rwlock_unlock_bug1() {
// There was a bug where when un-read-locking an rwlock that still has other
// readers waiting, we'd accidentally also let a writer in.
// That caused an ICE.
let l = Arc::new(RwLock::new(0));

let r1 = l.read().unwrap();
let r2 = l.read().unwrap();

// Make a waiting writer.
let l2 = l.clone();
thread::spawn(move || {
let mut w = l2.write().unwrap();
*w += 1;
});
thread::yield_now();

drop(r1);
assert_eq!(*r2, 0);
thread::yield_now();
thread::yield_now();
thread::yield_now();
assert_eq!(*r2, 0);
drop(r2);
}

fn check_rwlock_unlock_bug2() {
// There was a bug where when un-read-locking an rwlock by letting the last reader leaver,
// we'd forget to wake up a writer.
// That meant the writer thread could never run again.
let l = Arc::new(RwLock::new(0));

let r = l.read().unwrap();

// Make a waiting writer.
let l2 = l.clone();
let h = thread::spawn(move || {
let _w = l2.write().unwrap();
});
thread::yield_now();

drop(r);
h.join().unwrap();
}

fn main() {
check_conditional_variables_notify_all();
check_rwlock_unlock_bug1();
check_rwlock_unlock_bug2();
}

0 comments on commit 82b007e

Please sign in to comment.