Rust Scoped Threads 🦀 Rust Tutorial

preview_player
Показать описание
Rust provides a concept known as "scoped threads" in the standard library. You can use scoped threads to borrow heap-allocated memory, from the parent scope, and then return control back to the parent scope. If you don't use scopes to spawn threads, you will most likely run into issues with borrowing variables from the parent scope.

Please follow me on these other social channels!

All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names,trademarks and brands does not imply endorsement.

#rustlang #rust #rustdev #opensource #software #linux #devops #programming #rusty #dev #coding #codinglife #code #coder #ubuntu #ubuntulinux #appdev #developer
Рекомендации по теме
Комментарии
Автор

Thanks a lot Trevor, your channel is a gold mine. Greetings from France.

aszl
Автор

Your channel is definitely underrated!!! Deserves 100k subscriptions by now and more.

shahidyousuf
Автор

Thank you!! I watched these while i was bored and wanted to understand the differences in rust. I would live if u cover concepts like semaphores and condition variables in rust as well

siddarthsaha
Автор

Man thank you so much for this playlist i have devoted over a week and more into this playlist and thats the best thing to happen to me. I cant believe i am beginning to enjoy rust ❤

judevector
Автор

thank you man for these videos, they are really helping me out ❤

AhmedFalih-kjtt
Автор

one of best youtube teacher. tnx fot content ! :*

paralaxa
Автор

Pretty sure structs are also stack allocated, Altho the first_name String would be heap-allocated

FourTwentyMagic
Автор

This video was really helpful, thank you!

ians.
Автор

In your examples the threads only take pre-existing data snd print it. I am sure they could also calculate something new and print it. The question is: could they calculate something new and pass it on to the main thread that would then use it. If that is possible, how would one do that?

fsaldan
Автор

why cant use in the first example of (spawn of threads) removing the move key word and add & into person... and could you create video about smart pointers Mutex, Arc, Cell, OnceCell, OneCell, etc... btw i really like you videos. ♥

AhmedFalih-kjtt
Автор

didn't watch it but nice video anyways (:

ERAYKAAN
Автор

With scope and after removing "move" I could also use "person01.name" without any "&" in the closure. Maybe some Rust syntax-sugar going on

pub fn
let age = 42;
let person01 = Person {age, name: String::from("Trevor")};

// notice move is necessary to give the closure access to the parent variable
let my_closure = || {
println!("Closure vars:");
println!("age is {age}");
println!("name is {}", &person01.name); // &person01 is not necessary?
};

println!("age is {age}"); // runs OK
println!("name is {}", person01.name);


std::thread::scope(|scope: &Scope<'_, '_>| {
scope.spawn(my_closure);
});


println!("Thread is done");
println!("age is {age}");// runs OK
println!("name is {}", person01.name);
println!("finished main!")
}

Output:

age is 42
name is Trevor
Closure vars:
age is 42
name is Trevor
Thread is done
age is 42
name is Trevor
finished main!

pooyannajafi
welcome to shbcf.ru