Expand description
§Manually shared box
use std::thread;
use manual_share::SharedBox;
let b = Box::new(13);
let mut b = SharedBox::from_box(b);
let br = b.borrow();
let j1 = thread::spawn(move || {
println!("{}", br.get());
br
});
let br = b.borrow();
let j2 = thread::spawn(move || {
println!("{}", br.get() + 1);
br
});
b.try_return(j1.join().unwrap()).unwrap();
b.try_return(j2.join().unwrap()).unwrap();
let b = b.try_into_box().unwrap();
println!("{:?}", b);Structs§
- Shared
Box - A structure owning the original
Boxwhich can be used to create multipleSharedBoxRefto send to other thread. It uses a counter to record the number ofSharedBoxRefthat has been created and not given back. - Shared
BoxRef - A Reference to
SharedBoxthat can be sent to other threads.