Spinlocks Considered Harmful
In this post, I will be expressing strong opinions about a topic I have relatively little practical experience with, so feel free to roast and educate me in comments (link at the end of the post) :-) Specifically, I’ll talk about: I maintain once_cell crate, which is a synchronization primitive. It uses std blocking facilities under the hood (specifically, std::thread::park), and as such is not compatible with #[no_std]. A popular request is to add a spin-lock based implementation for use in #[no_std] environments: #61. More generally, this seems to be a common pattern in Rust ecosystem: For example, the lazy_static crate does this: github.com/rust-lang-nursery/lazy-static.rs/blob/master/src/core_lazy.rs I think this is an anti-pattern, and I am writing this blog post to call it out. A Spinlock is the simplest possible implementation of a mutex, its general form looks like this: Why we need Ordering::Acquire and Ordering::Release is very interesting, but beyond the scope of this articl
Happy new year 🎉! In this post, I will be expressing strong opinions about a topic I have relatively little practical experience with, so feel free to roast and educate me in comments (link at the end of the post) :-) Specifically, I’ll talk about: spinlocks, spinlocks in Rust with #[no_std] , priority inversion, CPU interrupts, and a couple of neat/horrible systemsy Rust hacks. Context I maintain once_cell crate, which is a synchronization primitive. It uses std blocking facilities under the hood (specifically, std::thread::park ), and as such is not compatible with #[no_std] . A popular req
Explore this link on the map →saved by
related reading
- Measuring Mutexes, Spinlocks and how Bad the Linux Scheduler Really is | Probably Danceprobablydance.com
- Unreliable Guide To Locking — The Linux Kernel documentationdocs.kernel.org
- Locking in WebKit | WebKitwebkit.org
- Concurrency Patterns in Embedded Rust - Ferrous Systemsferrous-systems.com
- Introduction to Real-time Systemsdesign.ros2.org
- async/await on embedded Rust - Ferrous Systemsferrous-systems.com
- Writing an OS in Rustos.phil-opp.com
- Using Threads to Run Code Simultaneously - The Rust Programming Languagedoc.rust-lang.org
- no_std async/await - soon on stable - Ferrous Systemsferrous-systems.com
- Async Rust Is A Bad Languagebitbashing.io
- Swift Concurrency Waits for No Onesaagarjha.com
- Mutex in std::sync - Rustdoc.rust-lang.org