File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
src/tools/miri/tests/many-seeds Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ cfg_if!(
136
136
// we only ever read from the tid if `tls_addr` matches the current
137
137
// TLS address. In that case, either the tid has been set by
138
138
// the current thread, or by a thread that has terminated before
139
- // the current thread was created . In either case, no further
139
+ // the current thread's `tls_addr` was allocated . In either case, no further
140
140
// synchronization is needed (as per <https://github.com/rust-lang/miri/issues/3450>)
141
141
tls_addr: Atomic <usize >,
142
142
tid: UnsafeCell <u64 >,
@@ -154,8 +154,12 @@ cfg_if!(
154
154
// NOTE: This assumes that `owner` is the ID of the current
155
155
// thread, and may spuriously return `false` if that's not the case.
156
156
fn contains( & self , owner: ThreadId ) -> bool {
157
+ // We must call `tls_addr()` *before* doing the load to ensure that if we reuse an
158
+ // earlier thread's address, the `tls_addr.load()` below happens-after everything
159
+ // that thread did.
160
+ let tls_addr = tls_addr( ) ;
157
161
// SAFETY: See the comments in the struct definition.
158
- self . tls_addr. load( Ordering :: Relaxed ) == tls_addr( )
162
+ self . tls_addr. load( Ordering :: Relaxed ) == tls_addr
159
163
&& unsafe { * self . tid. get( ) } == owner. as_u64( ) . get( )
160
164
}
161
165
Original file line number Diff line number Diff line change
1
+ #![ feature( reentrant_lock) ]
2
+ //! This is a regression test for
3
+ //! <https://rust-lang.zulipchat.com/#narrow/channel/269128-miri/topic/reentrant.20lock.20failure.20on.20musl>.
4
+
5
+ use std:: cell:: Cell ;
6
+ use std:: sync:: ReentrantLock ;
7
+ use std:: thread;
8
+
9
+ static LOCK : ReentrantLock < Cell < i32 > > = ReentrantLock :: new ( Cell :: new ( 0 ) ) ;
10
+
11
+ fn main ( ) {
12
+ for _ in 0 ..20 {
13
+ thread:: spawn ( move || {
14
+ let val = LOCK . lock ( ) ;
15
+ val. set ( val. get ( ) + 1 ) ;
16
+ drop ( val) ;
17
+ } ) ;
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments