Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created December 28, 2018 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/08b90ef2aac1c75f72009e9f51707154 to your computer and use it in GitHub Desktop.
Save rust-play/08b90ef2aac1c75f72009e9f51707154 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use std::thread;
struct Shitpointer(*mut i32);
unsafe impl Send for Shitpointer {}
fn main() {
let mut v: Vec<i32> = vec![1, 3, 3, 7];
let ptr_1 = Shitpointer(v.as_mut_ptr());
let ptr_2 = Shitpointer(v.as_mut_ptr());
let t_1 = thread::spawn(move || unsafe { *ptr_1.0.offset(0) += 1});
let t_2 = thread::spawn(move || unsafe { *ptr_2.0.offset(3) += 20});
t_1.join();
t_2.join();
println!("{:?}", v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment