Created
October 15, 2022 19:58
-
-
Save adililhan/d274f981863b93673e2351c975d23560 to your computer and use it in GitHub Desktop.
non-reentrant function in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::thread; | |
| use std::time::Duration; | |
| static mut SUM: i32 = 0; | |
| fn calculate(first: i32, second: i32) -> i32 { | |
| unsafe { | |
| SUM = first + second; | |
| } | |
| thread::sleep(Duration::from_secs(3)); | |
| unsafe { | |
| SUM | |
| } | |
| } | |
| fn main() { | |
| loop { | |
| println!("Result from main: {}\n", calculate(3, 5)); | |
| println!("---\n"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment