Atomic reference counting, and especially the ability of the compiler to guarantee (or, mostly guarantee) that these are thread safe at compile time is not common (as far as I know)
@@rico_1617 This is like saying "sorting algorithms aren't common". First, they are, and second they are algorithms and can always be implemented by hand and shipped on third party Libraries if needed. Atomic reference counting is extremely common in most languages implementation, Many garbage collectors work this way and in non GC languages they are most often included in the standard library. Even in a language like C that doesn't include these they are easy to implement. And no, the rust compiler doesn't guarantee that the Arc in the standard is thread safe as it is impossible to implement it without unsafe, the people who write the standard library do.
Well done. I really enjoy those videos of yours. Yes, please show us how to mitigate deadlocks. Or maybe, yeah I think that it might be a better idea, seeing how your channel seems to target novice programmers, maybe you should showcase how one can ran into deadlocks and/or circular dependencies. I know those are not necessarily closely related, but for me they feel like they should be mentioned and explained at the same time. Anyway, good job on bringing the official Rust book to life chapter by chapter. That is a really great service you do for the Rust programming language community. Keep it up.
One of the problems is to share large data structure shared by many threads. However, data is updated less frequently, it is mostly read access and therefore optimized for reads without using underlying mutex. Linux employs RCU for similar requirements in its kernel. An example in rust for similar purpose would be useful. Also, an special case would be a single writer thread which can use further optimization. If you can put together examples with crossbeam that achieves RCU like data sharing that would be awesome! Just a thought.
Hi Bogdan @letsgetrusty thank you so much for your videos! Watching them after reading the book really helps to cement the knowledge. I noticed around 20seconds into the video you said, "you can think of shared state concurrency as a one way data flow", but it should be message passing concurrency. Thank you so much for all you do!!!
I've been following your videos and they have been great at showing and teaching a lot of concepts in rust. I was wondering if you would be able to make a video on preventing deadlocks using Rust tools?
When writing complex async programs, Mutex is an absolute pain in the A. Heavily limits your methods of writing code. I always go for arc-swaps instead.
you don't actually import libraries. You import modules using mod, or crates using extern crate i suppose, (not needed anymore). If you use use, you put the used name into your namespace.
Is the rust's mutex the heavy c++like mutex? I found creating a new spinlock class that also implements wait functionality using std::atomic_flag in c++ and it is more lightweight for the application. Does rust have something like this?
Wondering why Rust allows you to use move mutable data like int, tupple, struct into other threads without any error and data seems to be copied. It is to quite confusing and compiler doesn't even warn about that. I was thinking that "move" transfers ownership but it seems that it creates copy at least in some scenarios. I suspect some unexpected magic behind "move".
Arc::clone() creates another handle to an existing Arc smart pointer. In most cases, random_variable.clone() copies byte for byte the value of random_variable into another variable.
@@climatechangedoesntbargain9140 the book says some_rc.clone() and Rc::clone(&some_rc) do the same (and Arc has the same API), but the latter is the preferred precisely to avoid the confusion of the .clone() functionality in other contexts.
@@isaacdefrain9595 oh. No, I don't have that feature in my setup (I used "Rust" and "rust-analyzer" and none of them was doing that). Maybe I need to configure something?...
@@zohnannor Do you have rustup installed? (Just to double-check, I disabled rust-analyzer and the underlining went away. I enabled it again and mutable variables are underlined again.)
@@isaacdefrain9595 rustup? Yes ofc, I am updating rust and it's components using rustup. Ok, I will check underlining in rust-analyzer tomorrow, thank you
📝 Get your *FREE Rust cheat sheet* : www.letsgetrusty.com/cheatsheet
Learning the Arc/Mutex combo was when I really felt the power of Rust. So cool to be able to get thread safe mutability checked by the compiler.
Mutexes were not invented by Rust. This is a trivial example that could be replicated in any other language.
Atomic reference counting, and especially the ability of the compiler to guarantee (or, mostly guarantee) that these are thread safe at compile time is not common (as far as I know)
@@rico_1617 This is like saying "sorting algorithms aren't common". First, they are, and second they are algorithms and can always be implemented by hand and shipped on third party Libraries if needed.
Atomic reference counting is extremely common in most languages implementation, Many garbage collectors work this way and in non GC languages they are most often included in the standard library. Even in a language like C that doesn't include these they are easy to implement.
And no, the rust compiler doesn't guarantee that the Arc in the standard is thread safe as it is impossible to implement it without unsafe, the people who write the standard library do.
Excellent vídeo. I will like to see the vídeos about dangling pointers and Send and Sync traits
Well done. I really enjoy those videos of yours.
Yes, please show us how to mitigate deadlocks.
Or maybe, yeah I think that it might be a better idea, seeing how your channel seems to target novice programmers, maybe you should showcase how one can ran into deadlocks and/or circular dependencies. I know those are not necessarily closely related, but for me they feel like they should be mentioned and explained at the same time.
Anyway, good job on bringing the official Rust book to life chapter by chapter. That is a really great service you do for the Rust programming language community. Keep it up.
Best explained Rust Videos I've seen so far. Thank you for your work. I'm really interested in more videos about concurrency patterns.
One of the problems is to share large data structure shared by many threads. However, data is updated less frequently, it is mostly read access and therefore optimized for reads without using underlying mutex. Linux employs RCU for similar requirements in its kernel. An example in rust for similar purpose would be useful. Also, an special case would be a single writer thread which can use further optimization. If you can put together examples with crossbeam that achieves RCU like data sharing that would be awesome! Just a thought.
Hi Bogdan @letsgetrusty thank you so much for your videos! Watching them after reading the book really helps to cement the knowledge. I noticed around 20seconds into the video you said, "you can think of shared state concurrency as a one way data flow", but it should be message passing concurrency. Thank you so much for all you do!!!
Yes please, dive deep video on Arc and Mutex related
oh man !! Need more concurrent stuff like this !! Make a series of video's ..ur effort is outstanding !!
PLEASE make an entire SERIES on concurrency and its modern development patterns + best practices
Nice video series❤ I would like to see more videos on concurrency in Rust, especially with the most popular crates in practice.
I've been following your videos and they have been great at showing and teaching a lot of concepts in rust. I was wondering if you would be able to make a video on preventing deadlocks using Rust tools?
This was awesome 👍 would love a dive into the tokio runtime and how it compares to the std lib's concurrency features
Yes please, make a Send & Sync video!
VERY good series ! 👍
Very helpful video. We want to see a video about Rust's concurrency in more details..... Plz make a video
Obviously we’d like you to teach us about deadlock mitigation strategies 🎉❤
Informative. Thanks a lot.
Pls make a vid on Send and Sync traits!!
Succinct. Not more or not less. And, a video on the careless handling of mutex and its disastrous effect will be fantastic.
This was my output when I tried step 1
m = Mutex { data: 6, poisoned: false, .. }
Because I'm using a newer version?...
I love your videos, the have great content.
When writing complex async programs, Mutex is an absolute pain in the A. Heavily limits your methods of writing code. I always go for arc-swaps instead.
you don't actually import libraries. You import modules using mod, or crates using extern crate i suppose, (not needed anymore).
If you use use, you put the used name into your namespace.
Please if we could get more complicated examples of parallel programming, updating of nested structures, deadlocks.... That would be awesome! :)
Please add video on deadlock prevention
How do you get rust-analyzer to update while you type and not on save?
Is the rust's mutex the heavy c++like mutex? I found creating a new spinlock class that also implements wait functionality using std::atomic_flag in c++ and it is more lightweight for the application. Does rust have something like this?
Small nitpick, but I think it would be clearer to use except with a description of the situation than unwrap.
Could you please make a video on MPSC channels? I just can't wrap my head around them 😔
i am commenting to get all those extra content you said we will get if i comment ! xD Dont remember the names xD
what chair do you use?
Wondering why Rust allows you to use move mutable data like int, tupple, struct into other threads without any error and data seems to be copied. It is to quite confusing and compiler doesn't even warn about that. I was thinking that "move" transfers ownership but it seems that it creates copy at least in some scenarios. I suspect some unexpected magic behind "move".
A trait called Copy.
Using Rc here is like overkill, is there any sensible method to achive same thing?
Probably better to handles errors properly instead of having the application panic? Anyhow aside from that good stuff
+1 for deadlocks
Concurrency sounds interesting, Arc::clone(...) vs ....clone()?
Arc::clone() creates another handle to an existing Arc smart pointer. In most cases, random_variable.clone() copies byte for byte the value of random_variable into another variable.
@@Supermath101 I meant the clone on an arc. It does the same, doesn't it?
@@climatechangedoesntbargain9140 the book says some_rc.clone() and Rc::clone(&some_rc) do the same (and Arc has the same API), but the latter is the preferred precisely to avoid the confusion of the .clone() functionality in other contexts.
At 4:12, the "let m" is not mutable. Then why underlying i32 is mutable using deref *num?
The mutex itself is immutable, the value inside not.
7:37
That inner scope is hurting my eyes
Ariaan was here
Hi! Why some variables in your code are underlined and what does that mean?
Mutable variables are underlined. Any VS Code Rust extension will do that for you.
@@isaacdefrain9595 oh. No, I don't have that feature in my setup (I used "Rust" and "rust-analyzer" and none of them was doing that). Maybe I need to configure something?...
@@zohnannor Do you have rustup installed?
(Just to double-check, I disabled rust-analyzer and the underlining went away. I enabled it again and mutable variables are underlined again.)
@@isaacdefrain9595 rustup? Yes ofc, I am updating rust and it's components using rustup. Ok, I will check underlining in rust-analyzer tomorrow, thank you
@@isaacdefrain9595 I figured it out. That was because of my theme
a comment down below.
Wow, what are the chances that ruclips.net/video/dGjuAFxvXnU/видео.html has similar examples as this video? I'm guessing you're using the same book
Joining the handles differently:
handles
.into_iter()
.for_each(|handle| handle.join().unwrap());