Comments (4)
Hmm, this is supposed to work — we go to some trouble to run thread-local destructors when a thread finishes, and we have a test for thread-locals dropping at the right time. I'll try to dig into this a bit more. Thanks for the report!
from shuttle.
#[test]
fn shuttle_issue() {
use shuttle::sync::*;
use core::cell::Cell;
let MU: &'static mut Mutex<usize> = Box::leak(Box::new(Mutex::new(0))); // a static_local here instead also works
shuttle::thread_local! {
static STASH: Cell<Option<MutexGuard<'_, usize>>> = Cell::new(None);
}
shuttle::check_random(|| {
shuttle::thread::spawn(|| {
STASH.with(|s| s.set(Some(MU.lock().unwrap())) );
});
STASH.with(|s| s.set(Some(MU.lock().unwrap())) );
}, 100);
}
is maybe a simpler reproduction of the reported deadlock. The std variant of the same test function doesn't deadlock. Maybe this is out of scope - turns out if you remove the spawn's thread_local then it will actually panic instead!
---- test::test::shuttle_issue stdout ----
thread 'test::test::shuttle_issue' panicked at 'assertion failed:(left != right)
left:Finished
,
right:Finished
', /home/charlie/.cargo/registry/src/github.com-1ecc6299db9ec823/shuttle-0.4.1/src/runtime/execution.rs:397:17
The Mutex (and channel, in my original example) are both outliving the shuttle scheduler since the static_local and 'static Mutex escape its closure, is maybe the root of the problem... If shuttle provided its own lazy_static that is re-initialized and dropped by the thread scheduler so the concurrency primitives don't escape this would also probably be less of an issue, though maybe that's just a poor man's version of #81
from shuttle.
Actually, you can probably just make an mpsc channel inside the shuttle::check_random scope and hand the receiver to a scoped thread to block on recv, and put the sender in a thread_local. In which case no concurrency primitives have a 'static lifetime or are escaping the closure...
from shuttle.
I think #88 will fix this. We weren't running the thread-local destructors for the main thread until the entire test ended. In your example that caused both spurious deadlocks (if the main thread held the lock) and the weird Finished
assertion failure (if the main thread tried to drop the lock, which happened after the entire test finished). Thanks for the simple reproducer!
from shuttle.
Related Issues (20)
- Failing schedule missing in output HOT 1
- Fix tracing spans
- "panicked while panicking" issues when drop handlers run concurrent code HOT 1
- `Once` breaks if moved HOT 1
- Rayon support HOT 1
- [TRACING] Improved testing of tracing functionality
- [TRACING] Add test which would catch the linked panic
- Use of Shuttle for Rust async and #[tokio::main] HOT 1
- Implement thread::scope HOT 2
- Run native blocking code HOT 2
- Replace Condvar epochs with clocks
- Suppress `generator` error on panic HOT 2
- Release a new version? HOT 1
- Provide more useful feedback for deadlocks HOT 2
- `wait_timeout` and friends shouldn't count as deadlocking
- Implement thread park(), unpark(), and panicking() HOT 1
- Is shuttle planning to support fork mode?
- Can't load replay schedule for max_steps failures HOT 2
- Make `future::JoinHandle::abort` actually cancel task HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shuttle.