-
Notifications
You must be signed in to change notification settings - Fork 217
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
fix: not panic in destructor #203
Conversation
following code can reproduce the problem if use std::thread;
use parking_lot::RwLock;
struct Bar(RwLock<()>);
impl Drop for Bar {
fn drop(&mut self) {
let _n = self.0.write();
}
}
thread_local! {
static B: Bar = Bar(RwLock::new(()));
}
fn main() {
thread::spawn(|| {
let a = RwLock::new(());
let _a = a.read();
B.with(|_| ());
}).join().unwrap();
} |
I can't reproduce the panic with your example code. Are you sure you are using the latest version of parking_lot? |
Did you enable |
Yes I enabled |
Can you try deleting your Cargo.lock to see if this helps? |
This seems to happen only on macOS, it is same issue as #114. |
Right I think I know what the problem is. Basically, the internal |
use std::thread;
use parking_lot::RwLock;
struct Bar(RwLock<()>);
impl Drop for Bar {
fn drop(&mut self) {
let _n = self.0.write();
}
}
thread_local! {
static B: Bar = Bar(RwLock::new(()));
}
fn main() {
thread::spawn(|| {
B.with(|_| ());
let a = RwLock::new(());
let _a = a.read();
}).join().unwrap();
} reversing init order of tld can make it reproduce on linux. |
I think a more general solution is needed here: the deadlock detector needs to be able to handle threads that have exited while still holding leaked locks. |
maybe not using thread_local? |
Actually after reviewing the code, I'm just going to go with your solution. |
bors r+ |
release_resource
should not panic. Becausewith_thread_data
may return aThreadData
on the stack, and it's empty.