computering

Spinlocks and You

Spinlocks and You

Spinlocks are a building block of concurrent programs. As long as you have more than one actor in your system, you’re going to need to be able to control access. We use spinlocks to maintain mutual exclusion - if process 1 is changing something in memory, we want to prevent all other processes from doing so. The idea is so simple that it seems too easy. A Basic (and Wrong) Spinlock Here’s our fist stab at a spinlock, badly written in C: