Latch implementations

#1 Blocking OS Mutex

  • Simple to use

  • Non-scalable (about 25ns per lick/unlock invocation)

  • Example std::mutex

#2 Test-and-Set Spin Latch (TAS)

  • Very efficient (single instruction to latch/unlatch)

  • Non-scalable, not cache friendly

  • Example: std::atomic<T>

#3 Reader-Writer Latch

  • Allows for concurrent readers

  • Must manage read/write queues to avoid starvation

  • Can be implemented on top of spinlocks

Last updated