코딩Coding/Rust☑︎Release☀︎Notes_New◎Version
Rust❤️1.63 아주 기대가 많이 되는 3가지 기능
내인생PLUS
2022. 7. 10. 22:48
728x90
1.63 아주 기대가 많이 됩니다.
1:static X: Mutex<String> = Mutex::new(String::new()); [Global variable 최고
/ 2: *X.lock().unwrap() = "Important information".to_string()
/ (오늘)3: Scoped threads 감사합니다. 언제나 최고
1:static X: Mutex<String> = Mutex::new(String::new()); [Global variable 최고 & / 2: *X.lock().unwrap() = "Important information".to_string()
https://youtu.be/T5OwV2HaH9E
Scoped threads
3. https://youtu.be/FfZJd-bpGdc
러스트 1.63 beta version 코드 입니다.
// rust 1.63 beta code ___
use std::sync::Mutex;
use std::thread;
fn main() {
let mut a = vec![1, 2, 3];
let mut x = 0;
thread::scope(|s| {
s.spawn(|| {
println!("Hello from the first scoped thread");
// We can borrow `a` here.
dbg!(&a);
});
s.spawn(|| {
println!("Hello from the first scoped thread");
// We can even butably borrow `x` here,
// because no other threads are using it.
x += a[0] + a[2];
});
println!("hello from the main thread");
});
// After the scope, we can modify and access our vatiables again:
a.push(4);
println!("print x : {}", a.len());
}
결과
Hello from the first scoped thread
Hello from the first scoped thread
[src/main.rs:13] &a = [
1,
2,
3,
]
hello from the main thread
print x : 4
https://twitter.com/m_ou_se/status/1538234055329718273?s=20&t=DRiTVzqhQ5Hz8fkpTMxnmg
반응형