File tree 1 file changed +3
-7
lines changed
tests/compile-fail/data_race
1 file changed +3
-7
lines changed Original file line number Diff line number Diff line change 1
1
// ignore-windows: Concurrency on Windows is not supported yet.
2
+ #![ feature( new_uninit) ]
2
3
3
4
use std:: thread:: spawn;
4
5
use std:: ptr:: null_mut;
@@ -10,11 +11,6 @@ struct EvilSend<T>(pub T);
10
11
unsafe impl < T > Send for EvilSend < T > { }
11
12
unsafe impl < T > Sync for EvilSend < T > { }
12
13
13
- extern "C" {
14
- fn malloc ( size : usize ) -> * mut u8 ;
15
- fn free ( ptr : * mut u8 ) ;
16
- }
17
-
18
14
pub fn main ( ) {
19
15
// Shared atomic pointer
20
16
let pointer = AtomicPtr :: new ( null_mut :: < usize > ( ) ) ;
@@ -33,7 +29,7 @@ pub fn main() {
33
29
// Uses relaxed semantics to not generate
34
30
// a release sequence.
35
31
let pointer = & * ptr. 0 ;
36
- pointer. store ( malloc ( std :: mem :: size_of :: < usize > ( ) ) as * mut usize , Ordering :: Relaxed ) ;
32
+ pointer. store ( Box :: into_raw ( Box :: < usize > :: new_uninit ( ) ) as * mut usize , Ordering :: Relaxed ) ;
37
33
} ) ;
38
34
39
35
let j2 = spawn ( move || {
@@ -45,6 +41,6 @@ pub fn main() {
45
41
j2. join ( ) . unwrap ( ) ;
46
42
47
43
// Clean up memory, will never be executed
48
- free ( pointer. load ( Ordering :: Relaxed ) as * mut _ ) ;
44
+ drop ( Box :: from_raw ( pointer. load ( Ordering :: Relaxed ) ) ) ;
49
45
}
50
46
}
You can’t perform that action at this time.
0 commit comments