Skip to content

Commit d39b2d8

Browse files
committed
Auto merge of #2267 - RalfJung:rustup, r=RalfJung
rustup I cannot reproduce rust-lang/rust#98493 so let's see what CI says.
2 parents e3d42e6 + a74c17d commit d39b2d8

File tree

3 files changed

+51
-47
lines changed

3 files changed

+51
-47
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a09c668c965f735f4cd59e7158662b9daa0b71ba
1+
8aab472d52ba7314dc193c73abcd384e2586123c

tests/pass/concurrency/sync.rs

+3-46
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn check_conditional_variables_notify_one() {
3535
let pair2 = pair.clone();
3636

3737
// Spawn a new thread.
38-
thread::spawn(move || {
38+
let t = thread::spawn(move || {
3939
thread::yield_now();
4040
let (lock, cvar) = &*pair2;
4141
let mut started = lock.lock().unwrap();
@@ -50,6 +50,8 @@ fn check_conditional_variables_notify_one() {
5050
while !*started {
5151
started = cvar.wait(started).unwrap();
5252
}
53+
54+
t.join().unwrap();
5355
}
5456

5557
/// Test that waiting on a conditional variable with a timeout does not
@@ -191,51 +193,6 @@ fn check_once() {
191193
}
192194
}
193195

194-
fn check_rwlock_unlock_bug1() {
195-
// There was a bug where when un-read-locking an rwlock that still has other
196-
// readers waiting, we'd accidentally also let a writer in.
197-
// That caused an ICE.
198-
let l = Arc::new(RwLock::new(0));
199-
200-
let r1 = l.read().unwrap();
201-
let r2 = l.read().unwrap();
202-
203-
// Make a waiting writer.
204-
let l2 = l.clone();
205-
thread::spawn(move || {
206-
let mut w = l2.write().unwrap();
207-
*w += 1;
208-
});
209-
thread::yield_now();
210-
211-
drop(r1);
212-
assert_eq!(*r2, 0);
213-
thread::yield_now();
214-
thread::yield_now();
215-
thread::yield_now();
216-
assert_eq!(*r2, 0);
217-
drop(r2);
218-
}
219-
220-
fn check_rwlock_unlock_bug2() {
221-
// There was a bug where when un-read-locking an rwlock by letting the last reader leaver,
222-
// we'd forget to wake up a writer.
223-
// That meant the writer thread could never run again.
224-
let l = Arc::new(RwLock::new(0));
225-
226-
let r = l.read().unwrap();
227-
228-
// Make a waiting writer.
229-
let l2 = l.clone();
230-
let h = thread::spawn(move || {
231-
let _w = l2.write().unwrap();
232-
});
233-
thread::yield_now();
234-
235-
drop(r);
236-
h.join().unwrap();
237-
}
238-
239196
fn park_timeout() {
240197
let start = Instant::now();
241198

tests/pass/concurrency/sync_nopreempt.rs

+47
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,53 @@ fn check_conditional_variables_notify_all() {
3535
}
3636
}
3737

38+
fn check_rwlock_unlock_bug1() {
39+
// There was a bug where when un-read-locking an rwlock that still has other
40+
// readers waiting, we'd accidentally also let a writer in.
41+
// That caused an ICE.
42+
let l = Arc::new(RwLock::new(0));
43+
44+
let r1 = l.read().unwrap();
45+
let r2 = l.read().unwrap();
46+
47+
// Make a waiting writer.
48+
let l2 = l.clone();
49+
thread::spawn(move || {
50+
let mut w = l2.write().unwrap();
51+
*w += 1;
52+
});
53+
thread::yield_now();
54+
55+
drop(r1);
56+
assert_eq!(*r2, 0);
57+
thread::yield_now();
58+
thread::yield_now();
59+
thread::yield_now();
60+
assert_eq!(*r2, 0);
61+
drop(r2);
62+
}
63+
64+
fn check_rwlock_unlock_bug2() {
65+
// There was a bug where when un-read-locking an rwlock by letting the last reader leaver,
66+
// we'd forget to wake up a writer.
67+
// That meant the writer thread could never run again.
68+
let l = Arc::new(RwLock::new(0));
69+
70+
let r = l.read().unwrap();
71+
72+
// Make a waiting writer.
73+
let l2 = l.clone();
74+
let h = thread::spawn(move || {
75+
let _w = l2.write().unwrap();
76+
});
77+
thread::yield_now();
78+
79+
drop(r);
80+
h.join().unwrap();
81+
}
82+
3883
fn main() {
3984
check_conditional_variables_notify_all();
85+
check_rwlock_unlock_bug1();
86+
check_rwlock_unlock_bug2();
4087
}

0 commit comments

Comments
 (0)