Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5142368
  • 博文数量: 1696
  • 博客积分: 10870
  • 博客等级: 上将
  • 技术积分: 18357
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-30 15:16
文章分类
文章存档

2017年(1)

2016年(1)

2015年(1)

2013年(1)

2012年(43)

2011年(17)

2010年(828)

2009年(568)

2008年(185)

2007年(51)

分类: LINUX

2010-05-28 00:28:12

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) |
给主人留下些什么吧!~~