Chapter 3. Latches
There are numerous data structures in Oracle's System Global Area (SGA) that need to be
accessed concurrently by many different database processes. It is essential that only one
process be able to modify any particular data structure at one time, and that the data
structure cannot be modified while it is being inspected. Oracle makes sure this does not
happen by protecting all SGA data structures with either locks or latches. (See Chapter 6,
for a description of the contents of the SGA and other memory areas.)
第三章 latches许多不同的数据库进程需要访问SGA，在ORACLE的SGA中有很多数据结构。在同一时刻，紧紧只让一个进程修改某个特定的数据结构是必要的，当数据结构被检查时，数据结构不能修改。Oracle 使用locks 或者latches来保护所有的SGA数据结构不发生这样事情。
3.1 Latches and Locks
Latches are the more restrictive mechanism, because they do not allow multiple
processes to inspect the protected data structure at the same time—they provide
for exclusive access only. Locks allow for better concurrency, because they may
be held in a shared mode when the data structure is simply being inspected.
 This is a simplification. The redo copy latches can be shared, but this is hardware
 这里简化了，redo copy latches能被共享，不过要依赖硬件。
Another significant difference between locks and latches is request queuing.
Requests for locks are queued if necessary and serviced in order, whereas latches
do not support request queuing. If a request to get a latch fails because the latch
is busy, the process just continues to retry until it succeeds. So latch requests are
not necessarily serviced in order.
Because a latch can only be held by one process at a time, and because there is no
inherent concept of queuing, the latch data structure itself is very simple—
essentially just a single location in memory representing the state of the latch.
And because the latch data structure is so simple, the functions to get and release
a latch have very little work to do. By contrast, the data structures for locks are
much more sophisticated because of their support for queuing and concurrency.
So the functions to get, convert, and release locks have correspondingly more
work to do.
Of course, it is necessary for Oracle to ensure that only one process at a time can
modify the latch and lock data structures themselves. For latches this is easy.
Because each latch is just a single location in memory, Oracle is able to use the
TEST AND SET, LOAD AND CLEAR, or COMPARE AND SWAP instructions of
the underlying hardware's instruction set for its latch get operations. Because
these are simple machine instructions that are guaranteed to be atomic, no other
locking mechanism is needed. This simplicity makes latch gets very efficient.
当然，在同一时刻只允许一个进程修改latch和lock它们本身的数据结构是必须的。对latches来说这是简单的。因为每一个latch仅仅有一个内存位置，Oracle能用硬件下指令设置的（instruction set 指令设置, CPU 可以执行的命令）TEST,SET,LOAD,CLEAR,COMPARE和SWAP来对latch进行操作。因为这是简单的保证原子的machine instructions，没有其他锁结构被需要，latch的操作是很高效率的。
Oracle's lock data structures, on the other hand, have several parts, and therefore
cannot be modified atomically. For this reason, Oracle actually protects operations
on locks with latches. The type of latch used varies depending on the type of lock.
For example, the cache buffer locks are indirectly protected by the cache buffers
chains latches, and the row cache enqueue locks are protected by the row cache
Oracle锁的数据结构，有几部分，所以不能被自动修改。由于这种原因，Oracle用latches保护在锁上的操作。这种latch多样化的使用依靠锁的类型。例如，the cache buffer locks间接的被the cache buffers chains latches保护。the row cache enqueue locks被the row cache objects latch保护。
Because latches are efficient, Oracle often uses a latch, rather than a lock and latch
combination, to protect data structures that are expected to be accessed only
briefly and intermittently.因为latches是很有效的，所以比起锁和latch combination，Oracle宁愿用一个latch来保护间歇地，暂时的数据结构。
来自 “ ITPUB博客 ” ，链接：http://blog.itpub.net/51726/viewspace-65965/，如需转载，请注明出处，否则将追究法律责任。