English 中文(简体)
可使用的障碍解决办法陷入僵局?
原标题:Reusable Barrier solution has a deadlock?

我读过“Semaphores小书”,在第41页中,可以解决可承受的障碍问题。 我面临的问题是,它为什么赢得僵局。

1 # rendezvous
2
3 mutex.wait()
4     count += 1
5     if count == n:
6         turnstile2.wait() # lock the second
7         turnstile.signal() # unlock the first
8 mutex.signal()
9
10 turnstile.wait() # first turnstile
11 turnstile.signal()
12
13 # critical point
14
15 mutex.wait()
16     count -= 1
17     if count == 0:
18         turnstile.wait() # lock the first
19         turnstile2.signal() # unlock the second
20 mutex.signal()
21
22 turnstile2.wait() # second turnstile
23 turnstile2.signal()

在这种解决办法中,从第15条到第20条之间,在保持导致僵局的休mut(第18条)的同时,呼吁等待是不好的习惯吗? 请解释。 谢谢。

最佳回答

。 第一个lock锁涉及为每一条read子加固反面,最后的read子进入(if = = n)为准备离开(见下文)打开了第二tile(n-1),并释放了(等待第10条)的 waiting。 然后,每个信号都传递给对方。

第2条互换锁与第1条类似,但缩略语<条码>(国名/国名) 进入旋转栅栏的最后一线(turnsless),为下一个批次(见上文)做准备,并释放(n-1)正在等待第22行的。 然后,每一条线向下信号。

因此,<代码>涡轮机将条目坐标至临界点,而<代码>turnsal2则协调从中提取。

不可能出现僵局:到(最后)线18时,<代码>turnsworth<>/code>被阻止由任何其他线索(所有线都在等待第22条)。 同样,<代码>涡轮机2

问题回答

暂无回答




相关问题
How to handle this Multithread situation and don t lock?

I have this situation: a Form with a System.Timer in it (with AutoReset = False). The form has its main thread and the timer its own thread too (nothing new here). When the user press a button I ...

Conversion deadlock caused by stored procedure

We ve got a problem with conversion deadlocking going on within one environment (the same proc + trigger works in at least four other environments). The stored procedure in question inserts a row ...

Deadlocks in concurrent transactions

I am trying to find an algorithm that detects deadlocks in concurrent transactions in a software. I have tried googling but have not found anything. Can someone point be to a good resource to follow ...

Win32 CreateWindow() call hangs in child thread?

I m working on a portability layer for OpenGL (abstracts the glX and wgl stuff for Linux and Windows)... Anyhow, it has a method for creating a Window... If you don t pass in a parent, you get a real ...

xml Column update and Locking in Sql Server

I have a few windwos services. They get xml column from Sql server manipulate and update it. Service A- Gets XML Service B- Gets XML Service A- Updates XML (it will be lost) Service B- Updates XML I ...

热门标签