Re: Latches

From: Mladen Gogala <>
Date: Fri, 9 Oct 2009 20:18:48 +0000 (UTC)
Message-ID: <>

On Fri, 09 Oct 2009 10:32:50 -0700, The Magnet wrote:

> Hi,
> Been looking around and reading on latches. I see references to
> 'parent' and 'child' latches. I'd like to understand the difference but
> I cannot find any good documentation on them. The Oracle documentation
> did not really explain why one would be acquired over the other.
> Thanks.
> Oh yeah, Sybrand, anything?

Latches are organized into hierarchical structures, called "trees" in order to prevent deadlocks. Let me explain this a bit: imagine you having 2 users, A and B, working on two tables, X and Y. User A locks the table X and wants to lock the table Y but cannot because it's already locked by the user B. So, user A has to wait for the user B to release the lock on the table Y. Now, user B wants to lock the table X but has to wait because user A already has the lock in place. User B now has to wait for the user A to release the lock. Both users are waiting one for another, to infinity. That situtation is called a circular wait or deadlock.

Now, imagine that both users were trying to lock tables in the same order, first X then Y. User A would have locked both tables, finished its work and allowed user B to proceed with his work.

Deadlocks in the Oracle kernel would be an extremely serious thing that needs to prevented at all cost. In order to facilitate that, there is an order in which a process can acquire a latch. If latch A must be acquired before acquiring the latch B, we say that the latch A is a parent of latch B.

There you have it. There is a great book, which brings back memory from college, called "Modern Operating Systema", and written by Andrew Tannenbaum. That book has the best explanation of synchronization mechanisms and critical sections that I've ever seen.

Received on Fri Oct 09 2009 - 15:18:48 CDT

Original text of this message