Skip to content

Commit

Permalink
Add test and comment for #203
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Jan 9, 2020
1 parent 4f9c50d commit 32d8f7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/src/parking_lot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,11 @@ mod deadlock_impl {
pub unsafe fn release_resource(key: usize) {
with_thread_data(|thread_data| {
let resources = &mut (*thread_data.deadlock_data.resources.get());

// There is only one situation where we can fail to find the
// resource: we are currently running TLS destructors and our
// ThreadData has already been freed. There isn't much we can do
// about it at this point, so just ignore it.
if let Some(p) = resources.iter().rposition(|x| *x == key) {
resources.swap_remove(p);
}
Expand Down
24 changes: 24 additions & 0 deletions src/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,4 +579,28 @@ mod tests {
assert_eq!(*(mutex.read()), *(deserialized.read()));
assert_eq!(contents, *(deserialized.read()));
}

#[test]
fn test_issue_203() {
struct Bar(RwLock<()>);

impl Drop for Bar {
fn drop(&mut self) {
let _n = self.0.write();
}
}

thread_local! {
static B: Bar = Bar(RwLock::new(()));
}

thread::spawn(|| {
B.with(|_| ());

let a = RwLock::new(());
let _a = a.read();
})
.join()
.unwrap();
}
}

0 comments on commit 32d8f7f

Please sign in to comment.