Latches and enqueues

posted Mar 9, 2011, 6:45 AM by Sachchida Ojha
Latches and enqueues are both types of locks.

latches are lightweight serialization devices. we try to get a latch, spin for a bit and
try again. so when getting a latch, we try and try and try -- we are not told that the
latch is available, we keep trying to get it (eg: not necessary a first come, first serve
lock). we use latches to serialize access to in memory data structures typically (like
SGA data structures)

enqueues are heavyweight serialization devices. if we cannot get an enqueue, we "go to
sleep" and when the enqueue is available -- we are told about it in a first come, first
serve manner. We use enqueues to perform row level locking for example.

A semaphore is an operating system supplied serialization device that one might use to
implemented latching or enqueues.

So, latches and enqueues are types of locks, semaphores a programming device one might
use to implement latching and enqueuing.