Share Rust Thread Data With Mutexes 🦀 Rust Tutorial

Поделиться
HTML-код
  • Опубликовано: 12 сен 2024

Комментарии • 16

  • @christopherpetersen342
    @christopherpetersen342 7 месяцев назад +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 9 месяцев назад

    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 11 месяцев назад +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 2 месяца назад

      Which book?

    • @harshitshukla36
      @harshitshukla36 2 месяца назад +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 6 месяцев назад

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

  • @irlshrek
    @irlshrek 7 месяцев назад +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 6 месяцев назад

    I love this!! this was a charm

  • @MathewBoorman
    @MathewBoorman 4 месяца назад

    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.

  • @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