> For the complete documentation index, see [llms.txt](https://til.notdu.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.notdu.com/database/intro-to-database-systems/multi-threaded-index-concurrency-control/latch-implementations.md).

# 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
