-
Notifications
You must be signed in to change notification settings - Fork 226
mpmc: add loom test for enqueue/dequeue contention #618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
fn issue_583_enqueue_loom() { | ||
const N: usize = 4; | ||
|
||
loom::model(|| { | ||
let q0 = loom::sync::Arc::new(Queue::<u8, N>::new()); | ||
for i in 0..N { | ||
q0.enqueue(i as u8).expect("new enqueue"); | ||
} | ||
eprintln!("start!"); | ||
|
||
let q1 = q0.clone(); | ||
loom::thread::spawn(move || { | ||
for k in 0..1000_000 { | ||
if let Some(v) = q0.dequeue() { | ||
q0.enqueue(v) | ||
.unwrap_or_else(|v| panic!("{k}: q0 -> q0: {v}, {:?}", to_vec(&*q0))); | ||
} | ||
} | ||
}); | ||
|
||
loom::thread::spawn(move || { | ||
for k in 0..1000_000 { | ||
if let Some(v) = q1.dequeue() { | ||
q1.enqueue(v) | ||
.unwrap_or_else(|v| panic!("{k}: q0 -> q0: {v}, {:?}", to_vec(&*q1))); | ||
} | ||
} | ||
}); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, adding a test using loom::thread::scope
from the linked PR also passes.
Thanks for working on fixing #583 Please add Regarding why the loom tests pass: you're misusing Here loom doesn't see any of the atomic operation so assumes all went fine. Also please use stable |
You're welcome <3
Sounds good, I just wanted to add the alternate implementation here first to make the comparison easier. I'll create a separate PR for the alternate implementation. I'll address the
This definitely sounds like it requires a separate PR. I'm new to the Since the failing conditions can be reached by normal unit-tests, I'll probably wait to implement the Edit: after a small experiment using a feature-gate for The
This probably means the |
Why? If it's just changes to unmerged changes, then it can (and should be) the same PR. Otherwise, it only creates unnecessary noise. Just modify your commits (if you have to) and force push to your branch. |
What I meant was that the
|
Adds a `loom` permutation test for `mpmmc::Queue::enqueue/dequeue` contention across threads. Related: rust-embedded#583 Co-authored-by: NODA Kai <https://github.com/nodakai> Co-authored-by: Sosthène Guédon <https://github.com/sosthene-nitrokey>
Adds a
loom
permutation test formpmmc::Queue::enqueue
contention across threads.Related: #583
Co-authored-by: NODA Kai @nodakai
Co-authored-by: Sosthène Guédon @sosthene-nitrokey