File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: sync:: debug_sync:: { RwLock , Mutex } ;
2
2
3
+ use super :: { LockHeldState , LockTestExt } ;
4
+
5
+ use std:: sync:: Arc ;
6
+ use std:: thread;
7
+
3
8
#[ test]
4
9
#[ should_panic]
5
10
#[ cfg( not( feature = "backtrace" ) ) ]
@@ -92,3 +97,22 @@ fn read_write_lockorder_fail() {
92
97
let _a = a. write ( ) . unwrap ( ) ;
93
98
}
94
99
}
100
+
101
+ #[ test]
102
+ fn test_thread_locked_state ( ) {
103
+ let mtx = Arc :: new ( Mutex :: new ( ( ) ) ) ;
104
+ let mtx_ref = Arc :: clone ( & mtx) ;
105
+ assert_eq ! ( mtx. held_by_thread( ) , LockHeldState :: NotHeldByThread ) ;
106
+
107
+ let lck = mtx. lock ( ) . unwrap ( ) ;
108
+ assert_eq ! ( mtx. held_by_thread( ) , LockHeldState :: HeldByThread ) ;
109
+
110
+ let thrd = std:: thread:: spawn ( move || {
111
+ assert_eq ! ( mtx_ref. held_by_thread( ) , LockHeldState :: NotHeldByThread ) ;
112
+ } ) ;
113
+ thrd. join ( ) . unwrap ( ) ;
114
+ assert_eq ! ( mtx. held_by_thread( ) , LockHeldState :: HeldByThread ) ;
115
+
116
+ std:: mem:: drop ( lck) ;
117
+ assert_eq ! ( mtx. held_by_thread( ) , LockHeldState :: NotHeldByThread ) ;
118
+ }
You can’t perform that action at this time.
0 commit comments