Treating Preemption as Garbage Collection for Memory Reordering in Lock-Free Code

Preemption is GC for memory reordering (2019)

8mpweiher💬 0
Treating Preemption as Garbage Collection for Memory Reordering in Lock-Free Code

I argue that we should treat preemption as a sunk cost, similar to garbage collection, to guarantee memory ordering in userspace without explicit barriers. By leveraging the serializing nature of interrupts on x86, we can implement efficient lock-free primitives like event counts and hazard pointers. This approach allows threads to sleep instead of spinning, integrating seamlessly with OS-level blocking while preserving lock-freedom and avoiding the overhead of traditional memory barriers.

"I now believe that preemption ought to be treated as a sunk cost, like garbage collection: we're already paying for it, so we might as well use it."

More from this day · 2026-07-11