Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions library/std/tests/sync/mpmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,23 +475,20 @@ fn stress_recv_timeout_two_threads() {
});

let mut recv_count = 0;
let mut got_timeout = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why not just make the sender thread have a while loop on a shared atomic value (like an Arc<AtomicBool>) that yields itself through thread::yield_now? Or I'm wondering if we could also use a shared Condvar that waits in the sender thread and the receiver thread is the one that sends a notification? That way we can guarantee that our receiver thread experiences a RecvTimeoutError::Timeout error after 10 ms and either set the atomic value to a state that the while loop from the sender thread will stop looping on or the sender thread just resumes its iteration in the for loop upon receiving a notification.

loop {
match rx.recv_timeout(timeout) {
Ok(n) => {
assert_eq!(n, 1usize);
recv_count += 1;
}
Err(RecvTimeoutError::Timeout) => {
got_timeout = true;
continue;
}
Err(RecvTimeoutError::Disconnected) => break,
}
}

assert_eq!(recv_count, stress);
assert!(got_timeout);
}

#[test]
Expand Down
3 changes: 0 additions & 3 deletions library/std/tests/sync/mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,23 +438,20 @@ fn stress_recv_timeout_two_threads() {
});

let mut recv_count = 0;
let mut got_timeout = false;
loop {
match rx.recv_timeout(timeout) {
Ok(n) => {
assert_eq!(n, 1usize);
recv_count += 1;
}
Err(RecvTimeoutError::Timeout) => {
got_timeout = true;
continue;
}
Err(RecvTimeoutError::Disconnected) => break,
}
}

assert_eq!(recv_count, stress);
assert!(got_timeout);
}

#[test]
Expand Down
Loading