【发布时间】:2013-07-19 11:32:41
【问题描述】:
这是我在操作系统考试中遇到的问题。我想不出它的正确答案。有人可以帮忙吗。Given 是一个同步代码,其中许多线程试图使用锁访问全局计数器 g-
if(lock==1)
wait(); //sleep this thread until some other thread wakes up this thread
else
lock=1; //enter in protected area
//access global counter g//
lock=0;
//wake up some other thread which is waiting for the lock to be released
上面的同步有什么问题?选择下面给出的任何选项
- 同步正常,可以正常运行。
- 只能在单处理器系统上运行,而不能在多处理器系统上运行。
- 不会在任何系统上运行
- 不能说。需要更多数据
【问题讨论】:
-
lock=1是什么意思?lock的设置和测试应该是原子的吗?锁定是否与等待队列交互? -
当有人访问变量时,我认为 lock=1。有人不在时为0
标签: operating-system semaphore