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
  • Наука та технологія

КОМЕНТАРІ • 19

  • @jmsdnns
    @jmsdnns 9 місяців тому +1

    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!

  • @ChidleyITCompute-ye7hc
    @ChidleyITCompute-ye7hc 3 місяці тому

    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.

    • @TrevorSullivan
      @TrevorSullivan  3 місяці тому

      Yes, Rust is an amazing language for performance! It's very efficient with CPU and memory resources. Thank you for your continued support! 😊❤️🦀

  • @MattPlncht
    @MattPlncht 3 місяці тому

    Amazing video, thanks a lot for explaining this topic!

  • @philipp332
    @philipp332 7 місяців тому

    Your content is awesome

  • @AhmedFalih-kj3tt
    @AhmedFalih-kj3tt 9 місяців тому +4

    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 ❤

    • @TrevorSullivan
      @TrevorSullivan  9 місяців тому

      Thanks for your kind feedback, Ahmed! I'm glad you are making progress! I'm on Discord @pcgeek86.

    • @AhmedFalih-kj3tt
      @AhmedFalih-kj3tt 9 місяців тому

      How about Arc with Mutex

  • @prashlovessamosa
    @prashlovessamosa 7 місяців тому

    Thanks for making this.

  • @farzadmf
    @farzadmf 9 місяців тому

    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

    • @TrevorSullivan
      @TrevorSullivan  9 місяців тому +1

      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!! 🦀

  • @roopeshsaravanan8609
    @roopeshsaravanan8609 5 місяців тому

    Could you provide the link to a github repo containing the code you wrote for the Rust playlist?

  • @davidlanday6102
    @davidlanday6102 Місяць тому

    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?

    • @TrevorSullivan
      @TrevorSullivan  Місяць тому

      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?

    • @TrevorSullivan
      @TrevorSullivan  Місяць тому

      I do see there's a crate called "core_affinity" that would be worth exploring.

    • @davidlanday6102
      @davidlanday6102 24 дні тому

      @@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…?

    • @davidlanday6102
      @davidlanday6102 24 дні тому

      @@TrevorSullivan oh nice! I will look at this. Thanks!

  • @GlobalYoung7
    @GlobalYoung7 3 місяці тому

    thank you