We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9e48787 commit eba471dCopy full SHA for eba471d
tests/run-pass/concurrency/thread_locals.rs
@@ -0,0 +1,48 @@
1
+#![feature(thread_local)]
2
+
3
+use std::thread;
4
5
+#[thread_local]
6
+static mut A: u8 = 0;
7
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
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
42
+ assert_eq!(*get_a_ref(), 5);
43
44
+ assert_eq!(B, 15);
45
+ assert_eq!(C, 24);
46
47
48
0 commit comments