Mesa vs. Hoare monitors
Need to be careful about the precise definition of signal and
wait.
Mesa-style: (Nachos, most real operating systems)
Signaller keeps lock, processor
Waiter simply put on ready queue, with no special priority.
(in other words, waiter may have to wait for lock)
Hoare-style: (most textbooks)
Signaller gives up lock, CPU to waiter; waiter runs
immediately
Waiter gives lock, processor back to signaller when it exits
critical section or if it waits again.
Above code for synchronized queuing happens to work with
either style, but for many programs it matters which you are
using. With Hoare-style, can change "while" in
RemoveFromQueue to an "if", because the waiter only gets
woken up if item is on the list. With Mesa-style monitors,
waiter may need to wait again after being
woken up, because some other thread may have acquired the
lock, and removed the item, before the original waiting thread
gets to the front of the ready queue.
This means as a general principle, you almost always need to
check the condition after the wait, with Mesa-style monitors (in
other words, use a "while" instead of an "if").
阅读(1554) | 评论(0) | 转发(0) |