-
Notifications
You must be signed in to change notification settings - Fork 114
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
Testing spinlock with Loom #162
Comments
Try increasing the value of |
You need to yield in the loop before retrying: https://docs.rs/loom/0.3.5/loom/thread/fn.yield_now.html This tells loom there is a loop going on and to try some other branches. |
So how did you test spinlocks in the end? I tried |
Loom is slow. Tokio's CI setup takes more than an hour because that's how long time our slowest loom test takes. You could try to mess with |
I see, thanks. You should add note about hour-scale "slow" in the docs. I was confident that it hang up. |
BTW, can it, theoretically, become multi-threaded? |
Yes, but nobody has put in the work. Generally, loom will print the iteration number as it runs, so you can use that to see whether it has hung up. (If running in test, make sure to enable prints in the test.) |
It does show! But for me, it just output everything at once, once test done. Thanks, I'll try with "pure" console. |
I had a similar issue involving a spin lock, and when I tried to minimize the problem I ran into some surprising (to me, an atomics novice) difference between the behavior of use loom::hint;
use loom::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::{Acquire, Relaxed, Release};
pub struct Lock {
locked: AtomicBool,
}
impl Lock {
pub fn lock(&self) {
while self.locked.swap(true, Acquire) {
hint::spin_loop();
}
}
pub fn unlock(&self) {
self.locked.store(false, Release);
}
}
#[test]
fn test_concurrent_logic() {
loom::model(|| {
let v1 = loom::sync::Arc::new(Lock::new());
let v2 = v1.clone();
let t1 = thread::spawn(move || {
v2.lock();
v2.unlock();
});
v1.lock();
v1.unlock();
t1.join().unwrap();
});
} But if I change |
Using |
I am trying to model a spinlock with Loom and running into a similar issue to #52 and #115. In particular, if I run my test
loom
withI get
thread panicked while panicking. aborting.
becauseModel exeeded maximum number of branches. This is often caused by an algorithm requiring the processor to make progress, e.g. spin locks.
.#52 says:
Does that mean that I can't test my spinlock with Loom, or do I need to add something to my spinlock implementation or my test to make it work with Loom? My spinlock implementation and Loom code are in this branch.
Thanks!
The text was updated successfully, but these errors were encountered: