You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add_to_count is unsound because it is a safe fn that, when called from multiple threads, results in data races which are UB.
Suggested fix: Either mention that it is unsound and this code should not be copied in prose, or change the example like so:
staticmutCOUNTER:u32 = 0;/// SAFETY: Must not be used to trigger data racesunsafefnadd_to_count(inc:u32){COUNTER += inc;}fnmain(){unsafe{add_to_count(3);println!("COUNTER: {}",COUNTER);}}
The text was updated successfully, but these errors were encountered:
main
branch to see if this has already been fixedURL to the section(s) of the book with this problem: https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html#accessing-or-modifying-a-mutable-static-variable
Description of the problem: In this example
add_to_count
is unsound because it is a safe fn that, when called from multiple threads, results in data races which are UB.Suggested fix: Either mention that it is unsound and this code should not be copied in prose, or change the example like so:
The text was updated successfully, but these errors were encountered: