Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::cell::UnsafeCell;
- use std::thread;
- struct ExtremelyBadIdea(pub *mut u128);
- unsafe impl Send for ExtremelyBadIdea { }
- unsafe impl Sync for ExtremelyBadIdea { }
- fn main() {
- const LEN: usize = 10000;
- let buf = UnsafeCell::new([0u128; LEN]);
- let mut handles = Vec::new();
- for _ in 0..100 {
- let handle = ExtremelyBadIdea(buf.get() as *mut u128);
- handles.push(thread::spawn(move || {
- let ptr = handle.0;
- for i in 0..LEN {
- unsafe { *ptr.add(i) = *ptr.add(i) + 4_999_999_999; }
- }
- }));
- }
- for h in handles {
- h.join().unwrap();
- }
- for i in 0..100 {
- println!("{}", unsafe { &*buf.get() }[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement