diff --git a/CHANGELOG.md b/CHANGELOG.md index 2252b91..93db39d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 window. - `CallbackHandle` now has a `must_use` hint that might help users discover the persist function. +- Fixed a deadlock that could occur when multiple threads were attempting to + execute change callbacks for the same dynamic at the same time. ### Added diff --git a/src/value.rs b/src/value.rs index f54a927..b136053 100644 --- a/src/value.rs +++ b/src/value.rs @@ -1437,11 +1437,10 @@ where impl<'a, T> DynamicMutexGuard<'a, T> { fn unlocked(&mut self, while_unlocked: impl FnOnce()) { - MutexGuard::unlocked(&mut self.guard, || { - let current_state = self.dynamic.during_callback_state.lock().take(); - while_unlocked(); - *self.dynamic.during_callback_state.lock() = current_state; - }); + let previous_state = self.dynamic.during_callback_state.lock().take(); + MutexGuard::unlocked(&mut self.guard, while_unlocked); + + *self.dynamic.during_callback_state.lock() = previous_state; } }