Rust

Scoped threads (thread::scope)

Në shqip: Thread-et me fushë

ShpjegimiSQ

std::thread::scope lejon thread-et të huazojnë të dhëna lokale pa Arc dhe pa move, sepse Rust-i garanton që të gjithë mbarojnë para se të dalë fusha.

EnglishEN

std::thread::scope lets threads borrow local data without Arc or move, because Rust guarantees they all finish before the scope ends.

Si ta mendosh

Si punëtorë që duhet ta mbarojnë punën para se të mbyllet punishtja.

Lexoje në anglisht

Like workers who must finish before the workshop closes.

Shembull kodirust

let notat = vec![9, 7, 10];
std::thread::scope(|s| {
    s.spawn(|| println!("Maks: {:?}", notat.iter().max()));
    s.spawn(|| println!("Shuma: {}", notat.iter().sum::<i32>()));
});

Terma të lidhur