Scoped threads in Rust 1.63

Published 2022-08-12

All Comments (19)
  • @darkfire2703
    Nice explanation on the new scoped threads.
    A little note on the static lifetime, as this is something that's not always clear to newcomers: A static lifetime doesn't mean "the value will life until the end of the program". It just means "the value must be able to live until the end of the program". This is normally fulfilled by either an actual static value, or an owned value. Since the owned value transfers ownership, it will live at least as long as the new scope. The value will still "die" (get dropped) when it gets out of scope at the end of the function. The lifetime is always necessary if you don't know when a given scope will end, like in the case of threads or async tasks. They could run until the end of the program, so the value must be able to live for the same amount of time.
    Unfortunately the compiler isn't able to detect when you join the thread, but that is exactly what the scoped threads try to fix (although it is still a bit more clunky)
  • @MrKeebs
    Wow, I dismissed it initially when reading the changelogs for 1.63 and I appreciate you made a video to explain this, turns out to be very useful. Thanks a lot for putting this together.
  • @marcoradocchia3461
    Beautiful explenation! Concise, yet explixative video. Thanks for sharing.
  • @jarrednorris
    I'm pretty new to rust (loving it though) and yet to write any multithreaded code but, wow does this make it look extremely easy and intuitive. Thanks for the video!
  • @TheUkearchy
    I'm building my first multi-threaded program (a simple ray tracer) and I missed this update. I think this is perfect for my program, it'll let me remove a bunch of static lifetime annotations. Thanks so much for posting this.
  • @rengaret
    Nice explenation I like it a lot. Keep doing videos cause you are very good at explanint stuff. I might even register to one of your courses when gamedev will be released
  • @JorgetePanete
    Someone check the subtitles, they occupy the whole screen at 0:00 and are turned on by default.
  • @fdncred
    This is an example of how to make nushell capture stdout & stderr, "do -i { git branch | complete }" in a folder that doesn't have a git repo.
  • You can think of lifetime as dependency, so, static lifetime basically means depending on a global/static variable, or even better, be an owner yourself, which depend on nothing. And for those 'a lifetime, it basically means the thing it depends on has a lifetime 'a. This is the mindset I have for dealing with lifetime constraints.
  • @semanser
    love the video! Unrelated question: what theme are you using in your editor and terminal?
  • @triforce42
    Are the closed captions scuffed for anyone else?
  • @zzzyyyxxx
    So could you say this is kind of like await for async functions, since scope() makes the rest of the program wait until it has finished?

    Corollay question, how would I use async with multithreading, any examples to look at?