Treating Preemption as Garbage Collection for Memory Reordering in Lock-Free Code
Preemption is GC for memory reordering (2019)

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.
- gblargg
If I understand this correctly, it basically has the second thread wait until the first one experiences a hardware interrupt, which implicitly synchronizes memory. This avoids the first thread from needing any synchronization primitives that would slow it down.
- Jweb_Guru
Oh boy this is a cool blog post. Encourage everyone to read it.
- preetham_rangu
same trick QSBR uses for lock-free reclamation, just framed at the OS scheduler level instead of userspace