Back to questions
JuniorTheoryCommon
What happens when this program is built and run?
use std::rc::Rc;
use std::thread;
fn main() {
let r = Rc::new(1);
thread::spawn(move || println!("{r}"));
}It does not compile
- Expecting
moveto make any value fit for a thread:movechanges how a value is captured, whileSenddecides whether it may go to another thread at all. - Expecting a run-time error from the shared counter:
Sendis checked by the compiler, soRcnever reaches a second thread.
- Which type replaces
Rchere, and what does it do differently with its count? - Why is a
Stringcaptured the same way accepted bythread::spawn?