Last active
February 25, 2020 20:34
-
-
Save tos-kamiya/b0899d7d752b8cb3489551cc41fd07cb to your computer and use it in GitHub Desktop.
crossbeam scopre test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://docs.rs/crossbeam/0.7.3/crossbeam/thread/index.html#structs | |
// need to add the following dependency to Cargo.toml | |
// | |
// [dependencies] | |
// crossbeam = "0.7" | |
use crossbeam::thread; | |
fn main() { | |
let mut var = vec![1, 2, 3]; | |
thread::scope(|s| { | |
s.spawn(|_| { | |
var.push(4); | |
println!("A child thread borrowing `var`: {:?}", var); | |
}); | |
}).unwrap(); | |
println!("Now got back ownership of `var`: {:?}", var); | |
} | |
// use std::thread; | |
// | |
// fn main() { | |
// let mut var = vec![1, 2, 3]; | |
// | |
// thread::spawn(move || { | |
// var.push(4); | |
// println!("A child thread borrowing `var`: {:?}", var); | |
// }); | |
// | |
// println!("Now got back ownership of `var`: {:?}", var); // compile error, ownership of `var` moved to the above thread. | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment