File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,26 @@ impl<T> Mutex<T> {
219
219
data : UnsafeCell :: new ( t) ,
220
220
}
221
221
}
222
+
223
+ /// Immediately drops the guard, and consequently unlocks the mutex.
224
+ ///
225
+ /// This function is equivalent to calling [`drop`] on the guard but is more self-documenting.
226
+ /// Alternately, the guard will be automatically dropped when it goes out of scope.
227
+ ///
228
+ /// ```
229
+ /// #![feature(mutex_unlock)]
230
+ ///
231
+ /// use std::sync::Mutex;
232
+ /// let mutex = Mutex::new(0);
233
+ ///
234
+ /// let mut guard = mutex.lock().unwrap();
235
+ /// *guard += 20;
236
+ /// Mutex::unlock(guard);
237
+ /// ```
238
+ #[ unstable( feature = "mutex_unlock" , issue = "81872" ) ]
239
+ pub fn unlock ( guard : MutexGuard < ' _ , T > ) {
240
+ drop ( guard) ;
241
+ }
222
242
}
223
243
224
244
impl < T : ?Sized > Mutex < T > {
You can’t perform that action at this time.
0 commit comments