首页 > 应用开发 > IT综合 > What is a latch?

What is a latch?

原创 IT综合 作者:hzh_hu 时间:2005-05-09 15:37:42 0 删除 编辑

Latches are low level serialization mechanisms used to protect shared
data structures in the SGA. The implementation of latches is operating
system dependent, particularly in regard to whether a process will wait
for a latch and for how long. A latch is a type  of a lock that can be
very quickly aquired and freed. Latches are typically used to prevent
more than one process from executing the same  piece of  code at  a
given time. Associated with each latch is a cleanup procedure that will
be called if a process  dies while holding  the latch.  Latches  have
an  associated level  that  is used to prevent deadlocks.  Once a
process acquires a latch at a certain level it  cannot subsequently
acquire a latch at a  level that is equal to  or less than that level
(unless it acquires it nowait).

Latches vs Enqueues:
Enqueues are another type of locking mechanism used in Oracle.  An
enqueue is a more sophisticated mechanism which permits several
concurrent processes to have varying degree of sharing of "known"
resources. Any object which can be concurrently used, can be protected
with enqueues. A good example is of locks on tables. We allow varying
levels of sharing on tables e.g. two processes can lock a table in
share mode or in share update mode etc. One difference is that the
enqueue is obtained using an OS specific locking mechanism. An enqueue
allows the user to store a value in the lock, i.e the mode in which we
are requesting it. The OS lock manager keeps track of the resources
locked. If a process cannot be granted the lock because it is
incompatible with the mode requested and the lock is requested with
wait, the OS puts the requesting process on a wait queue which is
serviced in FIFO. Another difference between latches and enqueues is
that in latches there is no ordered queue of waiters like in enqueues.
Latch waiters may either use timers to wakeup and retry or spin (only
in multiprocessors). Since all waiters are concurrently retrying
(depending on the scheduler), anyone might get the latch and
conceivably the first one to try might be the last one to get.[@more@]

来自 “ ITPUB博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

上一篇: 性能參數範例
请登录后发表评论 登录


  • 博文量
  • 访问量