@@ -366,6 +366,40 @@ impl<T: ?Sized> RwLock<T> {
366
366
self . poison . get ( )
367
367
}
368
368
369
+ /// Clear the poisoned state from a lock
370
+ ///
371
+ /// If the lock is poisoned, it will remain poisoned until this function is called
372
+ /// with a write guard. This allows recovering from a poisoned state and marking
373
+ /// that it has recovered. For example, if the value is overwritten by a known-good value,
374
+ /// then the mutex can be marked as un-poisoned. Or possibly, the value could be inspected to
375
+ /// determine if it is in a consistent state, and if so the poison is removed.
376
+ ///
377
+ /// # Examples
378
+ ///
379
+ /// ```
380
+ /// #![feature(mutex_unpoison)]
381
+ ///
382
+ /// use std::sync::{Arc, RwLock};
383
+ /// use std::thread;
384
+ ///
385
+ /// let lock = Arc::new(RwLock::new(0));
386
+ /// let c_lock = Arc::clone(&lock);
387
+ ///
388
+ /// let _ = thread::spawn(move || {
389
+ /// let _lock = c_lock.write().unwrap();
390
+ /// panic!(); // the mutex gets poisoned
391
+ /// }).join();
392
+ ///
393
+ /// let guard = lock.write().unwrap_err().into_inner();
394
+ /// RwLock::clear_poison(&guard);
395
+ /// assert_eq!(lock.is_poisoned(), false);
396
+ /// ```
397
+ #[ inline]
398
+ #[ unstable( feature = "mutex_unpoison" , issue = "none" ) ]
399
+ pub fn clear_poison ( guard : & RwLockWriteGuard < ' _ , T > ) {
400
+ guard. lock . poison . clear ( ) ;
401
+ }
402
+
369
403
/// Consumes this `RwLock`, returning the underlying data.
370
404
///
371
405
/// # Errors
0 commit comments