Share Rust Thread Data With Mutexes 🦀 Rust Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ต.ค. 2024

ความคิดเห็น • 16

  • @christopherpetersen342
    @christopherpetersen342 8 หลายเดือนก่อน +3

    It might have been nice to mention that the best practice is to lock the mutex (or any kind of lock) for as little time as possible. Putting the lock() call and (omg, really, no unlock yet?) drop() on either side of the add_assign() inside the loop would, theoretically lock and unlock the mutex during each loop and give control back and forth as quickly as possible. Otherwise, great content, and thanks for making the topic accessible!

  • @Mudclippa
    @Mudclippa 11 หลายเดือนก่อน

    Thanks for the video. I have a hard time learning from just text so it helps a lot to have a voice to the material.

  • @Qwerty-of4ox
    @Qwerty-of4ox ปีที่แล้ว +1

    Cool, was confused a bit while reading the book, but things made clearer here. So in the book, they have used Arc so share and update the data between the threads. In this video we have used "thread::scope" to share Mutex across threads and modify the data inside. So what I've understood is there are two ways we can reference the data from the main thread inside the spawned thread and then alter it inside the spawned thread.
    So what might be the differences between these approaches?. Like when to use Arc to share the data across the threads or when to use thread::scope to share the data?

    • @RahulYadav-dd7qe
      @RahulYadav-dd7qe 3 หลายเดือนก่อน

      Which book?

    • @harshitshukla36
      @harshitshukla36 3 หลายเดือนก่อน +1

      ​@@RahulYadav-dd7qe The rust book. Available on rust official website.

  • @AhmedFalih-kj3tt
    @AhmedFalih-kj3tt ปีที่แล้ว +2

    man i really thank you from my hear for these videos... finally i found someone that can explains rust with a simple way that i can understand

  • @mryoutuser
    @mryoutuser 7 หลายเดือนก่อน

    Thank you for your efforts really appreciate the clear voice and explanation and efforts put in the video

  • @irlshrek
    @irlshrek 8 หลายเดือนก่อน +1

    wouldnt you just derefence the MutexGuard to work with the data? is there some benefit to working with the MutexGuard's methods instead of derefencing it?

  • @cappedvillain2522
    @cappedvillain2522 7 หลายเดือนก่อน

    I love this!! this was a charm

  • @MathewBoorman
    @MathewBoorman 5 หลายเดือนก่อน

    Demo of join part is not doing what you think. The second thread never runs concurrently, join forces it to run now.
    Test wirh lock/unlock inside loop to show thread working concurrently.

    • @TrevorSullivan
      @TrevorSullivan  5 หลายเดือนก่อน

      Thanks for calling that out.

  • @AhmedFalih-kj3tt
    @AhmedFalih-kj3tt ปีที่แล้ว +2

    how about std::sync::mpsc ... is it an advance topic?

    • @TrevorSullivan
      @TrevorSullivan  ปีที่แล้ว +2

      I'm actually planning to do that topic today!!

    • @AhmedFalih-kj3tt
      @AhmedFalih-kj3tt ปีที่แล้ว +1

      @@TrevorSullivan ❤️🙏 I appreciate you