Skip to content

Instantly share code, notes, and snippets.

@adililhan
Created October 15, 2022 19:58
Show Gist options
  • Select an option

  • Save adililhan/d274f981863b93673e2351c975d23560 to your computer and use it in GitHub Desktop.

Select an option

Save adililhan/d274f981863b93673e2351c975d23560 to your computer and use it in GitHub Desktop.
non-reentrant function in Rust
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