Skip to content

Commit e0df0ae

Browse files
committed
Make example code use global variables
Because `fn main()` was added automatically, the variables were actually local statics.
1 parent f5e991b commit e0df0ae

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/libstd/sync/mod.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@
1818
//! Considering the following code, operating on some global static variables:
1919
//!
2020
//! ```rust
21-
//! # static mut A: u32 = 0;
22-
//! # static mut B: u32 = 0;
23-
//! # static mut C: u32 = 0;
24-
//! # unsafe {
25-
//! A = 3;
26-
//! B = 4;
27-
//! A = A + B;
28-
//! C = B;
29-
//! println!("{} {} {}", A, B, C);
30-
//! C = A;
31-
//! # }
21+
//! static mut A: u32 = 0;
22+
//! static mut B: u32 = 0;
23+
//! static mut C: u32 = 0;
24+
//!
25+
//! fn main() {
26+
//! unsafe {
27+
//! A = 3;
28+
//! B = 4;
29+
//! A = A + B;
30+
//! C = B;
31+
//! println!("{} {} {}", A, B, C);
32+
//! C = A;
33+
//! }
34+
//! }
3235
//! ```
3336
//!
3437
//! It appears _as if_ some variables stored in memory are changed, an addition
@@ -42,8 +45,6 @@
4245
//! - first store to `C` might be moved before the store to `A` or `B`,
4346
//! _as if_ we had written `C = 4; A = 3; B = 4;`
4447
//!
45-
//! - last store to `C` might be removed, since we never read from it again.
46-
//!
4748
//! - assignment of `A + B` to `A` might be removed, the sum can be stored in a
4849
//! in a register until it gets printed, and the global variable never gets
4950
//! updated.

0 commit comments

Comments
 (0)