Spinlocks Considered Harmful

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 request is to add a spin-lock based implementation for use in #[no_std] environments: #61.