违反非原子等待的互斥 - 信号量
我正在做一个“操作系统”主题,但我无法理解这个问题:
我们被要求演示如果不以原子方式处理 wait(s),如何会违反互斥。 (信号量实现)
现在,我看到这可能会导致错误的计数,导致程序认为它拥有比实际更多的可用资源,
但我似乎无法理解这将如何违反互斥的概念:(
谁能阐明或指出我正确的方向?
I'm doing an 'operating systems' topic and I can't get my head around this:
We have been asked to demonstrate how mutual exclusion can be violated if wait(s) is not handled atomically. (semaphore implementation)
Now, I see how this may cause an incorrect count, resulting in the program thinking it has more resources available than it truly does,
But I can't seem to grasp the concept of how this will violate mutual exclusion :(
Can anyone shed some light or point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Google 上排名第二的结果(这个问题排名第一):http:// /web.cs.wpi.edu/~cs502/f98/Waltham/hw2soln.html
请参阅问题 2。
Number two result on Google (this question was number one): http://web.cs.wpi.edu/~cs502/f98/Waltham/hw2soln.html
See question 2.
让我们假设下面是 wait(S) 的代码(galvin 的示例)
如果 wait(S) 操作不是原子操作,即 wait(S) 内的所有操作都不会立即执行。两个线程 T1 和 T2 正在执行同一操作 wait(S) 同时进行,因为 wait(S) 操作不是原子操作,T1 更新 S 的值,同时 T2 更新(覆盖 T1 写入的值),S 值的实际减量为 2但同时执行导致仅减少 1 这种情况称为竞争条件,这会导致计数不正确,导致程序认为它拥有比实际更多的可用资源。您可以在此处阅读有关竞争条件的更多信息 http://en.wikipedia.org/wiki/Race_condition
Let us assume that below is the code for wait(S)(example of galvin)
If the wait(S) operation is not atomic i.e all operation inside wait(S) are not executed all at once.Two thread T1 and T2 are executing the same operation wait(S) simultaneously since the wait(S) operation is not atomic and T1 updates the value of S and at the same time T2 updates(overwrite the value written by T1) the actual decrement in the value of S is 2 but the simultaneously execution causes decrement in only 1 This scenario is known as race condition and this causes an incorrect count, resulting in the program thinking it has more resources available than it truly does.you can read more about race condition here http://en.wikipedia.org/wiki/Race_condition