File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -228,6 +228,17 @@ impl<T: Send> Mutex<T> {
228
228
Err ( TryLockError :: WouldBlock )
229
229
}
230
230
}
231
+
232
+ /// Determine whether the lock is poisoned.
233
+ ///
234
+ /// If another thread is active, the lock can still become poisoned at any
235
+ /// time. You should not trust a `false` value for program correctness
236
+ /// without additional synchronization.
237
+ #[ inline]
238
+ #[ unstable( feature = "std_misc" ) ]
239
+ pub fn is_poisoned ( & self ) -> bool {
240
+ self . inner . poison . get ( )
241
+ }
231
242
}
232
243
233
244
#[ unsafe_destructor]
@@ -458,12 +469,14 @@ mod test {
458
469
#[ test]
459
470
fn test_mutex_arc_poison ( ) {
460
471
let arc = Arc :: new ( Mutex :: new ( 1 ) ) ;
472
+ assert ! ( !arc. is_poisoned( ) ) ;
461
473
let arc2 = arc. clone ( ) ;
462
474
let _ = Thread :: scoped ( move || {
463
475
let lock = arc2. lock ( ) . unwrap ( ) ;
464
476
assert_eq ! ( * lock, 2 ) ;
465
477
} ) . join ( ) ;
466
478
assert ! ( arc. lock( ) . is_err( ) ) ;
479
+ assert ! ( arc. is_poisoned( ) ) ;
467
480
}
468
481
469
482
#[ test]
Original file line number Diff line number Diff line change @@ -237,6 +237,17 @@ impl<T: Send + Sync> RwLock<T> {
237
237
Err ( TryLockError :: WouldBlock )
238
238
}
239
239
}
240
+
241
+ /// Determine whether the lock is poisoned.
242
+ ///
243
+ /// If another thread is active, the lock can still become poisoned at any
244
+ /// time. You should not trust a `false` value for program correctness
245
+ /// without additional synchronization.
246
+ #[ inline]
247
+ #[ unstable( feature = "std_misc" ) ]
248
+ pub fn is_poisoned ( & self ) -> bool {
249
+ self . inner . poison . get ( )
250
+ }
240
251
}
241
252
242
253
#[ unsafe_destructor]
@@ -451,12 +462,14 @@ mod tests {
451
462
#[ test]
452
463
fn test_rw_arc_poison_ww ( ) {
453
464
let arc = Arc :: new ( RwLock :: new ( 1 ) ) ;
465
+ assert ! ( !arc. is_poisoned( ) ) ;
454
466
let arc2 = arc. clone ( ) ;
455
467
let _: Result < uint , _ > = Thread :: scoped ( move || {
456
468
let _lock = arc2. write ( ) . unwrap ( ) ;
457
469
panic ! ( ) ;
458
470
} ) . join ( ) ;
459
471
assert ! ( arc. write( ) . is_err( ) ) ;
472
+ assert ! ( arc. is_poisoned( ) ) ;
460
473
}
461
474
462
475
#[ test]
You can’t perform that action at this time.
0 commit comments