u/fluzz142857in r/rust • Recommends
On “If I use one shared AtomicBool as an indicator, do I need to worry about the ordering?”
111K subscribers • 38 videos on Hallway
Advanced. Deep dive for people who know the field.
109K views5 years ago7 recommendations
Systems programmingProgramming languagesRustConcurrency and parallelismMemory management
Jon Gjengset explains Rust's atomic types and memory ordering, demonstrating how to implement concurrency primitives like mutexes.
In this episode of Crust of Rust, we go over Rust's atomic types, including the mysterious Ordering enum. In particular, we explore the std::sync::atomic module, and look at how its components can be used to implement concurrency primitives like mutexes. We also investigate some of the gotchas and sometimes counter-intuitive behaviors of the atomic primitives with different memory orderings, as well as strategies for testing for and debugging errors in concurrent code. Introduction What are atomics? The Memory Model AtomicUsize Questions so far Implementing a (bad) Mutex Our Mutex works! Pesky thread interleavings compare_exchange Mitigating compare_exchange contention compare_exchange_weak Ordering::Relaxed Ordering::Acquire/Release The fetch_ methods Ordering::SeqCst Breather ThreadSanitizer loom Atomic fences volatile AtomicPtr Atomics through FFI Consume ordering? Closing thoughts You can read more about Rust's memory model in the Rust reference at doc.rust-lang.org/nightly/reference/memory-model.html and in the C++ memory model documentation at en.cppreference.com/w/cpp/atomic/memory_order. Live version with chat: youtube.com/watch?v=0Vq2aJxwB1oWhat people say. Recommended as an in-depth explanation of Rust atomics and memory ordering.
u/fluzz142857in r/rust • Recommends
On “If I use one shared AtomicBool as an indicator, do I need to worry about the ordering?”
u/masklinnin r/rust • Recommends
On “Miri now produces relaxed memory effects”
u/WrongJudgment6in r/rust • Recommends
On “Question: Find the right ordering for Atomics”
u/kam821in r/rust • Recommends
On “What is the use of AtomicBool?”
u/seftontychoin r/rust • Recommends
On “Rust has exposed my lack of knowledge on how computers work.”
u/Top-Ant493in r/rust • Recommends
On “My (few) reservations about Rust”
u/DzenanJupicin r/rust • Mentions
On “Hey Rustaceans! Got an easy question? Ask here (29/2021)!”
u/stdusrin r/rust • Mentions
On “Sharing counters among threads”
u/hardfau18in r/rust • Mentions
On “Is int and bool are thread safe?”
u/__maccas__in r/rust • Mentions
On “When you learned rust did you take notes or swallowed the whole book at once?”