Skip to content

Commit a4cbbdd

Browse files
committed
merge parking test into general synchronization test
1 parent b350c80 commit a4cbbdd

File tree

3 files changed

+30
-39
lines changed

3 files changed

+30
-39
lines changed

tests/run-pass/concurrency/parking.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/run-pass/concurrency/parking.stderr

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/run-pass/concurrency/sync.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,34 @@ fn check_rwlock_unlock_bug2() {
312312
h.join().unwrap();
313313
}
314314

315+
fn park_timeout() {
316+
let start = Instant::now();
317+
318+
thread::park_timeout(Duration::from_millis(200));
319+
// Normally, waiting in park/park_timeout may spuriously wake up early, but we
320+
// know Miri's timed synchronization primitives do not do that.
321+
322+
assert!((200..500).contains(&start.elapsed().as_millis()));
323+
}
324+
325+
fn park_unpark() {
326+
let t1 = thread::current();
327+
let t2 = thread::spawn(move || {
328+
thread::park();
329+
thread::sleep(Duration::from_millis(200));
330+
t1.unpark();
331+
});
332+
333+
let start = Instant::now();
334+
335+
t2.thread().unpark();
336+
thread::park();
337+
// Normally, waiting in park/park_timeout may spuriously wake up early, but we
338+
// know Miri's timed synchronization primitives do not do that.
339+
340+
assert!((200..500).contains(&start.elapsed().as_millis()));
341+
}
342+
315343
fn main() {
316344
check_barriers();
317345
check_conditional_variables_notify_one();
@@ -327,4 +355,6 @@ fn main() {
327355
check_once();
328356
check_rwlock_unlock_bug1();
329357
check_rwlock_unlock_bug2();
358+
park_timeout();
359+
park_unpark();
330360
}

0 commit comments

Comments
 (0)