mpmc: add loom test for enqueue/dequeue contention#618
mpmc: add loom test for enqueue/dequeue contention#6180xllx0 wants to merge 2 commits intorust-embedded:mainfrom
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.
There was a problem hiding this comment.
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>
|
Closing in favor of #620 |
Adds a
loompermutation test formpmmc::Queue::enqueuecontention across threads.Related: #583
Co-authored-by: NODA Kai @nodakai
Co-authored-by: Sosthène Guédon @sosthene-nitrokey