upcarta
  • Sign In
  • Sign Up
  • Explore
  • Search

A Firehose of Rust, for busy people who know some C++

  • Video
  • Jun 1, 2021
  • #ComputerProgramming
Jack O'Connor
@oconnor663
(Speaker)
www.youtube.com
Watch on Youtube
2,627 84 min
1 Recommender
1 Mention
Slides: https://jacko.io/firehose_of_rust The slower version of this talk (2h32m): https://youtu.be/FSyfZVuD32Y Contents: 0:00:00 introduction 0:04:03 references and mutable aliasi... Show More

Slides: https://jacko.io/firehose_of_rust
The slower version of this talk (2h32m): https://youtu.be/FSyfZVuD32Y

Contents:
0:00:00 introduction
0:04:03 references and mutable aliasing
0:06:54 reference lifetime examples
0:22:12 mutable aliasing examples
0:50:16 move semantics
1:10:50 Arc Mutex String

Links from screenshots in slides:
https://godbolt.org/z/891s6z4Tb
https://youtu.be/xnqTKD8uD64?t=1380
https://godbolt.org/z/fK1WchMYf
https://youtu.be/lkgszkPnV8g?t=1750

Errata:
- The example raw pointer code shown at 26:33 is valid today according to Miri, but it's not the best approach, and it's possible that it will become invalid before the rules for unsafe Rust finally stabilize. The worry is that creating a temporary shared reference on line 3 implies that the mutable reference on line 2 is definitely dead, which could mean that the raw pointer on line 2 is also dead in some sense. Interpreting things this way requires "provenance" analysis, and a future version of Rustc might be allowed to do that analysis. A more conservative approach would be to use .as_mut_ptr() to get a pointer to the first element and then .add() to get a pointer to the second element, without creating any extra references to the array.
- At 56:20 I described both C++ copy constructors and the Rust .clone() method as making a "deep copy". That's sometimes the right way to think about it, but not when pointers and references get involved. Indeed, the final section relies on shallow cloning to share a reference-counted object across threads. C++ and Rust behave very similarly here, and understanding that ".clone() works like a C++ copy constructor" tells you most of what you need to know about a wide variety of different types.
- At 1:05:49 I said that Mutex in Rust needs a heap allocation on Linux because of how the underlying system calls work. That's mostly incorrect. It's true that a futex can't be moved while locked, and that does matter for std::mutex in C++. But it doesn't actually matter in Rust, because a Mutex is borrowed and immovable while it's locked. Instead, the issue in Rust is that POSIX doesn't guarantee that a pthread_mutex_t is movable (although many implementations are movable in practice). See https://twitter.com/m_ou_se/status/1403413967846977538. (Update: As of Rust 1.62, released in June 2022, Mutex on Linux creates a futex directly and no longer needs a heap allocation. Mutex still uses pthreads and heap allocation on some other Unix systems.)

(From Youtube)

Show Less
Recommend
Post
Save
Complete
Collect
Mentions
See All
Tim McNamara @timClicks ยท Apr 3, 2023
  • Post
  • From Twitter
There's no shame in sharing this Jack - it's an extremely informative talk.
  • upcarta ©2025
  • Home
  • About
  • Terms
  • Privacy
  • Cookies
  • @upcarta