Building a Tiny Mutex
kprotty.me·169w
Preview
Report Post

Lets say you’re writing your own synchronization primitives for whatever reason and you need a small, fast Mutex.

Could be that you made your own OS and pthread’s API ain’t looking too good. Could be that you want something faster than what your platform’s libc provides through pthread. Could be that you’re doing it for fun (the best reason), it doesn’t matter.

In a perfect world, you just write a simple spin-lock and be done with it. But scheduling isn’t that easy and such naïve solutions can have pretty bad or awkward consequences. In this post I’ll walk through designing and understanding what makes a good mutex. I’ll assume you know some about atomic memory operations and their memory orderings (pretty thicc assumption, I know).

Spin Locks

You love to see ‘em. First…

Similar Posts

Loading similar posts...