Message Passing With Rust MPSC Channels 🦀 Rust Tutorial
Вставка
- Опубліковано 29 чер 2024
- Rust provides a construct known as "channels," which enables developers to pass data between different threads. Rust channels act very similarly to message queues. When you create a channel, Rust returns handles to both a "sender" (aka. transmitter), and a "receiver." The sender can be used with the .send() method to add messages into the channel (aka. queue). The thread can take ownership of the receiver handle, and use the .recv() or .recv_timeout() methods to pull data (messages) off the channel. Because Rust channels use generics, you can send / receive any type of data between threads.
🤯 Rust Programming Playlist 🦀 • Rust Programming Tutor...
📖 Rust std::sync::mpsc docs ➡️ doc.rust-lang.org/std/sync/mpsc/
Visual Studio Code ➡️ code.visualstudio.com
Rust Website ➡️ rust-lang.org
Rustup Installer ➡️ rustup.rs
Rust Docs ➡️ doc.rust-lang.org/book
Please follow me on these other social channels!
➡️ trevorsullivan.net
➡️ github.com/pcgeek86
➡️ / pcgeek86
➡️ / trevorsullivan
➡️ / trevorsoftware
➡️ tiktok.com/pcgeek86
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 - Наука та технологія
I have been watching all of your videos in the Rust series and just wanted to say that they're fantastic! I appreciate how much time you're putting in. I've been coding over 20 years, but I am new to Rust, so I appreciate very much that you are to the point and that you don't assume we're all beginner programmers. Thank you!
Concurrent and parallel programming is a key skill because computers can only boost their performance by adding more cores. This means that programmers need to know how to write code that can run on multiple cores simultaneously and efficiently. I think that rust is probably the best programming language for this. Thank you for these last few videos.
Yes, Rust is an amazing language for performance! It's very efficient with CPU and memory resources. Thank you for your continued support! 😊❤️🦀
Amazing video, thanks a lot for explaining this topic!
Your content is awesome
I really enjoy your video… i have learnt how channels work and made me more confident to work with rust as js/ts programmer… my favourite thing is you provide simple explanations that i can understand and i love how you provide many situations that can help us… i really enjoy your videos.. thank you so much for that work… i hope you have discord so i can contact you ❤
Thanks for your kind feedback, Ahmed! I'm glad you are making progress! I'm on Discord @pcgeek86.
How about Arc with Mutex
Thanks for making this.
GREAT video (like the others); you're doing an amazing job with these tutorials.
I must say: doing this in Go feels SUPER natural and smooth, and comparing the amount of work that needs to be done to achieve something similar in Rust seems wayyyy more complicated and involved
Thanks for your kind words!
You're definitely right that not everything is straightforward in Rust, but it does give you granular control. The way that errors are handled in Rust and Go is also very different. Both languages have excellent performance, so it's a matter of picking the tool that works best for you! Rust on!! 🦀
Could you provide the link to a github repo containing the code you wrote for the Rust playlist?
does rust make any guaruntees about channel / thread allocation? For example, can I ensure that when I spawn two threads that they are on the same cpu core?
That's a good question. Is there any reason that you wouldn't trust the OS thread scheduler to handle this appropriately? Why are you wanting to manually manage thread affinity from your Rust application? Are you building an OS in Rust?
I do see there's a crate called "core_affinity" that would be worth exploring.
@@TrevorSullivan not making an OS, but core affinity could be useful in a heavy compute (HPC) type of application. I might be wrong, but on hpc systems (while they have a control plane to manage resources over a network connection) you might want to ensure that you are not oversubscribing your resources or that a process utilizes only a certain number of cores and threads etc…?
@@TrevorSullivan oh nice! I will look at this. Thanks!
thank you