File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
tests/run-pass/concurrency Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ #![ feature( thread_local) ]
2
+
3
+ use std:: thread;
4
+
5
+ #[ thread_local]
6
+ static mut A : u8 = 0 ;
7
+ #[ thread_local]
8
+ static mut B : u8 = 0 ;
9
+ static mut C : u8 = 0 ;
10
+
11
+ unsafe fn get_a_ref ( ) -> * mut u8 {
12
+ & mut A
13
+ }
14
+
15
+ fn main ( ) {
16
+
17
+ unsafe {
18
+ let x = get_a_ref ( ) ;
19
+ * x = 5 ;
20
+ assert_eq ! ( A , 5 ) ;
21
+ B = 15 ;
22
+ C = 25 ;
23
+ }
24
+
25
+ thread:: spawn ( || {
26
+ unsafe {
27
+ assert_eq ! ( A , 0 ) ;
28
+ assert_eq ! ( B , 0 ) ;
29
+ assert_eq ! ( C , 25 ) ;
30
+ B = 14 ;
31
+ C = 24 ;
32
+ let y = get_a_ref ( ) ;
33
+ assert_eq ! ( * y, 0 ) ;
34
+ * y = 4 ;
35
+ assert_eq ! ( A , 4 ) ;
36
+ assert_eq ! ( * get_a_ref( ) , 4 ) ;
37
+
38
+ }
39
+ } ) . join ( ) . unwrap ( ) ;
40
+
41
+ unsafe {
42
+ assert_eq ! ( * get_a_ref( ) , 5 ) ;
43
+ assert_eq ! ( A , 5 ) ;
44
+ assert_eq ! ( B , 15 ) ;
45
+ assert_eq ! ( C , 24 ) ;
46
+ }
47
+
48
+ }
You can’t perform that action at this time.
0 commit comments