The 8-Byte Lock: Packing a Reader-Writer Lock Into 64 Bits
csharp
dotnet
concurrency
database
typhon
A reader-writer lock with a shared counter, three classes of waiter, an owning thread id, a contention flag and a state machine — all inside a single ulong, published with one CompareExchange. The bit layout, the measured 19 ns, the fairness ladder that keeps writers from starving, and why a lock that gets written to disk is worth building a second, smaller one for.