diff --git a/examples/bare4.rs b/examples/bare4.rs index 4861ecd3751885a27517f48048122906cca75527..66090d88ac90941eb5973c099605748434b2955b 100644 --- a/examples/bare4.rs +++ b/examples/bare4.rs @@ -27,8 +27,8 @@ use address::*; #[inline(always)] fn read_u32(addr: u32) -> u32 { - unsafe { core::ptr::read_volatile(addr as *const _) } - //core::ptr::read_volatile(addr as *const _) +// unsafe { core::ptr::read_volatile(addr as *const _) } + core::ptr::read_volatile(addr as *const _) } #[inline(always)] @@ -101,10 +101,15 @@ fn main() { // 2. comment out line 30 and uncomment line 31 (essentially omitting the `unsafe`) // what was the error message and explain why, // +// >> Call to unsafe function requires unsafe function or block // ** your answer here ** // // digging a bit deeper, why do you think `read_volatile` is declared `unsafe` // (https://doc.rust-lang.org/core/ptr/fn.read_volatile.html, for some food for thought ) +// +// >> While volatile will not be re-ordered by the compiler, +// this still doesn't prevent something to start changing the value +// as the program may try to read (since read may not be an atomic operation) // ** your answer here ** // // commit your answers (bare4_2)