From e0df0ae734ec97ad7cc67cf6bed0d142275571b9 Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Sun, 16 Sep 2018 12:56:44 +0300 Subject: Make example code use global variables Because `fn main()` was added automatically, the variables were actually local statics. --- src/libstd/sync/mod.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index e06e2994069..df153561b4b 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -18,17 +18,20 @@ //! Considering the following code, operating on some global static variables: //! //! ```rust -//! # static mut A: u32 = 0; -//! # static mut B: u32 = 0; -//! # static mut C: u32 = 0; -//! # unsafe { -//! A = 3; -//! B = 4; -//! A = A + B; -//! C = B; -//! println!("{} {} {}", A, B, C); -//! C = A; -//! # } +//! static mut A: u32 = 0; +//! static mut B: u32 = 0; +//! static mut C: u32 = 0; +//! +//! fn main() { +//! unsafe { +//! A = 3; +//! B = 4; +//! A = A + B; +//! C = B; +//! println!("{} {} {}", A, B, C); +//! C = A; +//! } +//! } //! ``` //! //! It appears _as if_ some variables stored in memory are changed, an addition @@ -42,8 +45,6 @@ //! - first store to `C` might be moved before the store to `A` or `B`, //! _as if_ we had written `C = 4; A = 3; B = 4;` //! -//! - last store to `C` might be removed, since we never read from it again. -//! //! - assignment of `A + B` to `A` might be removed, the sum can be stored in a //! in a register until it gets printed, and the global variable never gets //! updated. -- cgit 1.4.1-3-g733a5