Concurrency in Rust - Sharing State

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

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

  • @letsgetrusty
    @letsgetrusty  3 года назад +5

    📝 Get your *FREE Rust cheat sheet* : www.letsgetrusty.com/cheatsheet

  • @Erfa
    @Erfa 3 года назад +54

    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.

    • @marcossidoruk8033
      @marcossidoruk8033 2 месяца назад

      Mutexes were not invented by Rust. This is a trivial example that could be replicated in any other language.

    • @rico_1617
      @rico_1617 День назад

      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)

    • @marcossidoruk8033
      @marcossidoruk8033 День назад

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

  • @joaoalves1359
    @joaoalves1359 3 года назад +22

    Excellent vídeo. I will like to see the vídeos about dangling pointers and Send and Sync traits

  • @DrIngo1980
    @DrIngo1980 3 года назад +25

    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.

  • @michaelhugi8761
    @michaelhugi8761 3 года назад +4

    Best explained Rust Videos I've seen so far. Thank you for your work. I'm really interested in more videos about concurrency patterns.

  • @kibudude
    @kibudude Год назад +3

    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.

  • @paulorubebe7308
    @paulorubebe7308 10 месяцев назад

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

  • @murugarajuperumalla5508
    @murugarajuperumalla5508 2 года назад +2

    Yes please, dive deep video on Arc and Mutex related

  • @bjugdbjk
    @bjugdbjk 2 года назад +1

    oh man !! Need more concurrent stuff like this !! Make a series of video's ..ur effort is outstanding !!

  • @rolandawillis5229
    @rolandawillis5229 3 года назад +2

    PLEASE make an entire SERIES on concurrency and its modern development patterns + best practices

  • @alectonz2257
    @alectonz2257 Год назад

    Nice video series❤ I would like to see more videos on concurrency in Rust, especially with the most popular crates in practice.

  • @saadsatter8702
    @saadsatter8702 9 месяцев назад

    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?

  • @spongechameleon6940
    @spongechameleon6940 2 года назад +2

    This was awesome 👍 would love a dive into the tokio runtime and how it compares to the std lib's concurrency features

  • @ringo.gg.
    @ringo.gg. 2 года назад

    Yes please, make a Send & Sync video!

  • @oborderies
    @oborderies 9 месяцев назад

    VERY good series ! 👍

  • @mdkhorshed2043
    @mdkhorshed2043 2 года назад

    Very helpful video. We want to see a video about Rust's concurrency in more details..... Plz make a video

  • @pricesmith1793
    @pricesmith1793 Год назад

    Obviously we’d like you to teach us about deadlock mitigation strategies 🎉❤

  • @malharvora1281
    @malharvora1281 2 года назад +1

    Informative. Thanks a lot.

  • @anjakalaba1424
    @anjakalaba1424 2 года назад +1

    Pls make a vid on Send and Sync traits!!

  • @nirmalyasengupta6883
    @nirmalyasengupta6883 Год назад

    Succinct. Not more or not less. And, a video on the careless handling of mutex and its disastrous effect will be fantastic.

  • @bryson2662
    @bryson2662 2 года назад +2

    This was my output when I tried step 1
    m = Mutex { data: 6, poisoned: false, .. }
    Because I'm using a newer version?...

  • @everardosanchez
    @everardosanchez 2 года назад +1

    I love your videos, the have great content.

  • @m4heshd
    @m4heshd 6 месяцев назад +1

    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.

  • @denizsincar29
    @denizsincar29 18 дней назад

    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.

  • @bzzzvzzze
    @bzzzvzzze Год назад

    Please if we could get more complicated examples of parallel programming, updating of nested structures, deadlocks.... That would be awesome! :)

  • @piusono
    @piusono 2 года назад

    Please add video on deadlock prevention

  • @brianhume6724
    @brianhume6724 2 года назад +1

    How do you get rust-analyzer to update while you type and not on save?

  • @sc5shout
    @sc5shout 3 года назад

    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?

  • @QazCetelic
    @QazCetelic Год назад

    Small nitpick, but I think it would be clearer to use except with a description of the situation than unwrap.

  • @syedahkam7164
    @syedahkam7164 3 года назад

    Could you please make a video on MPSC channels? I just can't wrap my head around them 😔

  • @harsharaghu8004
    @harsharaghu8004 2 года назад

    i am commenting to get all those extra content you said we will get if i comment ! xD Dont remember the names xD

  • @icaroamorim3123
    @icaroamorim3123 Год назад

    what chair do you use?

  • @netify6582
    @netify6582 2 года назад

    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".

  • @umut8244
    @umut8244 2 года назад

    Using Rc here is like overkill, is there any sensible method to achive same thing?

  • @johnwilliams7999
    @johnwilliams7999 2 года назад

    Probably better to handles errors properly instead of having the application panic? Anyhow aside from that good stuff

  •  2 года назад

    +1 for deadlocks

  • @climatechangedoesntbargain9140
    @climatechangedoesntbargain9140 3 года назад

    Concurrency sounds interesting, Arc::clone(...) vs ....clone()?

    • @Supermath101
      @Supermath101 3 года назад +1

      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
      @climatechangedoesntbargain9140 3 года назад

      @@Supermath101 I meant the clone on an arc. It does the same, doesn't it?

    • @ChumX100
      @ChumX100 2 года назад

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

  • @Sunil-yz7ig
    @Sunil-yz7ig Год назад

    At 4:12, the "let m" is not mutable. Then why underlying i32 is mutable using deref *num?

    • @marcossidoruk8033
      @marcossidoruk8033 2 месяца назад

      The mutex itself is immutable, the value inside not.

    • @Schaex1
      @Schaex1 Месяц назад

      7:37

  • @GolangDojo
    @GolangDojo 3 года назад

    That inner scope is hurting my eyes

  • @arimcbrown
    @arimcbrown 2 года назад

    Ariaan was here

  • @zohnannor
    @zohnannor 3 года назад

    Hi! Why some variables in your code are underlined and what does that mean?

    • @isaacdefrain9595
      @isaacdefrain9595 3 года назад

      Mutable variables are underlined. Any VS Code Rust extension will do that for you.

    • @zohnannor
      @zohnannor 3 года назад

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

    • @isaacdefrain9595
      @isaacdefrain9595 3 года назад

      @@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.)

    • @zohnannor
      @zohnannor 3 года назад

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

    • @zohnannor
      @zohnannor 3 года назад

      @@isaacdefrain9595 I figured it out. That was because of my theme

  • @hanyanglee9018
    @hanyanglee9018 6 месяцев назад

    a comment down below.

  • @hishbouabdallah5917
    @hishbouabdallah5917 8 месяцев назад

    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

  • @martinmaurer3935
    @martinmaurer3935 Год назад

    Joining the handles differently:
    handles
    .into_iter()
    .for_each(|handle| handle.join().unwrap());