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