Concurrency in Rust - Creating Threads

  Рет қаралды 59,206

Let's Get Rusty

Let's Get Rusty

Күн бұрын

Пікірлер: 36
@letsgetrusty
@letsgetrusty 3 жыл бұрын
📝 Get your *FREE Rust cheat sheet* : www.letsgetrusty.com/cheatsheet
@sonicsplasher
@sonicsplasher 11 ай бұрын
Just 15 videos to go. You got this
@everyhandletaken
@everyhandletaken 3 жыл бұрын
I was expecting that to be more complicated.. nice 👍🏻
@magnoelmagnifico957
@magnoelmagnifico957 3 жыл бұрын
me too haha
@jonathanmoore5619
@jonathanmoore5619 3 жыл бұрын
That's the next part...
@everyhandletaken
@everyhandletaken 3 жыл бұрын
@@jonathanmoore5619 calm before the storm ☺️
@veirt
@veirt 3 жыл бұрын
Ikr, the chapter before (smart pointers) was hell for me who came from high level languages
@everyhandletaken
@everyhandletaken 3 жыл бұрын
@@veirt I can relate, most things are hell for me 😂
@yousefh4939
@yousefh4939 3 жыл бұрын
i will rewatch all the videos after it get complete it make me happy to see you made new video every time i log in youtube
@exoticcoder5365
@exoticcoder5365 3 жыл бұрын
Very useful & clear on why we need to move ownwership into the closure 👍🏻Thank you
@aloysberger9482
@aloysberger9482 3 жыл бұрын
Good work mate, thank you for these videos they're very good. Keep up the good work.
@kishanbsh
@kishanbsh 3 жыл бұрын
Eagerly awaiting your video on async await and futures
@herrxerex8484
@herrxerex8484 3 жыл бұрын
Keep it up , man !!! awesome as always
@ClaudioParraGonzalez
@ClaudioParraGonzalez 3 жыл бұрын
Sweet stuff! Thanks, man!
@----__---
@----__--- 3 жыл бұрын
eagerly waiting for listening to the async by you
@aqua3418
@aqua3418 3 жыл бұрын
Don't you mean you're _awaiting_ for him to explain it? **nudge nudge**
@mybdretaemch3409
@mybdretaemch3409 Жыл бұрын
this is very interesting!! nice explanation!
@MrGreen-kq4ds
@MrGreen-kq4ds 3 жыл бұрын
great video - thanks! do u plan to cover async rust at some point?
@letsgetrusty
@letsgetrusty 3 жыл бұрын
Yes!
@bgdjovan
@bgdjovan Жыл бұрын
Really useful!
@func0der
@func0der 2 жыл бұрын
Thank you very much for this clear video. I learned so much.
@spongechameleon6940
@spongechameleon6940 2 жыл бұрын
Is there an idiomatic way to pass the same data in heap to multiple threads for reads? Like by wrapping the data in Rc?
@cat-.-
@cat-.- Жыл бұрын
std::sync::Arc
@emvdl
@emvdl 3 жыл бұрын
Thank you! 👍
@alanaxotla9112
@alanaxotla9112 3 жыл бұрын
This is amazing
@jabuci
@jabuci 2 жыл бұрын
Can you make a video about scoped threads? New in 1.63.
@TON-vz3pe
@TON-vz3pe 2 жыл бұрын
How is race condition and dead lock. prevented in this example?
@mdrealiyev
@mdrealiyev Жыл бұрын
Hello. Evertig is good and understandable. But I have a question. How can I call thread::spawn inside implemented class and pass self safety?
@KokahZ777
@KokahZ777 7 ай бұрын
I pattern I found is to wrap your struct (call it A) data in some Inner struct that is Arc in A That way you can pass a self clone to your functions which just duplicates the pointer but not the actual data
@saadabbasi2063
@saadabbasi2063 3 жыл бұрын
Please make a video on using Tokio
@letsgetrusty
@letsgetrusty 3 жыл бұрын
I will eventually!
@emilfilipov169
@emilfilipov169 2 жыл бұрын
I find this confusing and I can't find anyone who has explained it yet. So, the thread takes ownership of your variable, say v, for example. You "can't" use it outside of the thread, but yet you can. fn main() { let limit: i32 = 5; let handle = thread::spawn(move || { for n in 1..=limit { println!("Spawned, {}", n * n); thread::sleep(Duration::from_millis(1)) } }); for n in 1..=limit { println!("Main, {}", n * n); thread::sleep(Duration::from_millis(1)) } handle.join().unwrap(); } Why does this code run? If one thread has ownership of the variable, doesn't that mean nothing else can own it?
@kylezwarich
@kylezwarich Жыл бұрын
The move keyword for closure tells Rust compiler to keep "limit" in scope for the duration of the spawned thread, and handle.join().unwrap() says to run all threads through to completion. So every loop iteration the spawned thread asks "is limit still a thing", Rust says "it is a thing because you still need it"; even though the main thread might have finished processing its batch of loops already, the other still needs access to 'limit'. If me and you order spaghetti and meatballs, but I hate noodles and you hate meatballs, we can split the dish and we both have a satisfying meal, but we have to share the fork. Just because I'm finished all the meatballs doesn't necessarily mean our dinner is done--using the move keyword and the thread::join() says "we both need the fork so don't get rid of it until we're both done the plate"
@janedoe6182
@janedoe6182 Жыл бұрын
"As soon as you type new Thread(), it’s over; your project already has legacy code" (c) Stephen Cleary In general creating new OS threads in modern programs - bad idea. Except specialized pools serving async I/O
@hobbes5043
@hobbes5043 2 жыл бұрын
I thought this video was alright. I wish you did more than just rehash the textbook though. Some different examples would have helped.
@alexisgavidia3141
@alexisgavidia3141 Жыл бұрын
hi, i have a question if !l.iter().any(|x| x.file_name == j.file_name) { //copy file to tmp folder. let y = j.clone(); let ha = thread::spawn(move || async move { cp_to_tmp_and_pod( cmd_start_raw_capture_ecs, y, i, pods, n, &path_on_the_host, ) .await; }); n += 1; l.push(j); ha.join().unwrap().await; } } ha.join().unwrap().await; i cant run it the function wiout the await. and i want to run but the main thred need to wait until this fisnih.
Concurrency in Rust - Message Passing
9:26
Let's Get Rusty
Рет қаралды 43 М.
Rust's second most complicated feature explained
7:48
Let's Get Rusty
Рет қаралды 39 М.
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
Object Oriented Programming in Rust
7:10
Let's Get Rusty
Рет қаралды 44 М.
Rust Threading Basics 🦀 Rust Tutorial
28:26
Trevor Sullivan
Рет қаралды 10 М.
2 Years Of Learning C | Prime Reacts
22:24
ThePrimeTime
Рет қаралды 331 М.
Traits in Rust
11:44
Let's Get Rusty
Рет қаралды 111 М.
8 deadly mistakes beginner Rust developers make
14:14
Let's Get Rusty
Рет қаралды 180 М.
Async Rust Is A Bad Language | Prime Reacts
28:46
ThePrimeTime
Рет қаралды 112 М.
All Rust features explained
21:30
Let's Get Rusty
Рет қаралды 337 М.
The Perfect Dependency - SQLite Case Study
19:32
Tom Delalande
Рет қаралды 99 М.
What Makes Rust Different?
12:38
No Boilerplate
Рет қаралды 209 М.
CONCURRENCY IS NOT WHAT YOU THINK
16:59
Core Dumped
Рет қаралды 129 М.
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН