左撇子和右撇子哲学家的混合体,一个棘手的问题?
mixture of left-handed and right-handed philosophers, a tricky questions?
Lemma 1: we know at any table with a mixture of left-handed and right-handed
philosophers, deadlock cannot occur. I very familiar with it proofs.
我 运行 最近在采访中遇到了以下问题。
有 5 位哲学家围坐在一起 table。每两个哲学家之间有一根筷子。每个哲学家需要两根筷子吃饭。我们有两种类型的哲学家:左撇子和右撇子。左撇子先用左手拿筷子。右撇子先用右手拿筷子。假设 5 位哲学家中至少有 1 位左撇子和至少 1 位右撇子。哪一个是正确的:
a) independent from the combination of placement philosophers at round
table, there is no deadlock. (I sure True)
b) if all of the philosophers simultaneously take the first
chopsticks, there is a deadlock. (I thin this is true because in
implication if we have a-->b and a is false a-->b is true., and in
this option there is no way to all philosopher simultaneously take the
first chopsticks, so the whole statement is true.)
哪位高手可以帮帮我,我的论点是真的吗?
Edit 1: I add the proof for Lemma1: (but the question mentioned above
has some differences. )
First observe that due to the pattern of resource acquisition around
the table there is only one possible wait-cycle, i.e., the cycle
involving all philosophers. So assume such a deadlock. Every
philosopher must be waiting, by which we mean waiting for a chopstock
held by another. Thus all chopsticks must be held. If our table has a
mixture of left-handed and right-handed philosophers, there must be at
least one pair of adjacent philosophers of opposite handedness. First
assume a left-handed philosopher (“Lenny”) seated to the left of a
right-handed philosopher (“Roger”). Because all chopsticks must be
held, either Lenny or Roger must hold the chopstick which is between
them. If Lenny holds it, that is his “right chopstick,” so he must
previously have acquired the chopstick to his left. Thus Lenny holds
two chopsticks, and is not waiting to acquire any (he is eating), so
there is not a deadlock. If Roger holds the chopstick which is between
them, that is his “left chopstick,” so he must previously have
acquired the chopstock to his right, etc. If we call the previous case
the “outward reaching” case, then the “inward reaching” case is a
right-handed philosopher seated to the left of a left-handed
philosopher. Again, if we have a deadlock, all chopsticks must be
held, so one of them holds the chopstick between them. This means that
the other one holds no chopsticks, since the one between them is the
first one each will try to acquire (either Roger reached right and got
it, or Lenny reached left and got it; the other is waiting for it
before reaching in the outward direction). If there are n philosphers
and n chopsticks, all chopsticks held, but one philosopher holds zero
chopsticks, then n−1 philosophers hold n chopsticks. Some philospher
must hold two chopsticks; that philosopher is not waiting (he is
eating), so there is no deadlock.
这里有一个例子:
一位左撇子哲学家,四位右撇子哲学家:
如果所有人都拿起一根筷子,左撇子哲学家赢得了对他左手边筷子的争夺,他有一根筷子,而他右手边的一根仍然是空闲的。在下一次迭代中,他或他右手边的邻居将拿起最后一根空闲的筷子。无论哪种方式,至少有一位哲学家有两根筷子吃饭。 --> 没有死锁
假设没有哲学家试图拿起 "outward" 筷子,除非他已经拿到 "inward" 一根。
现在我们来剖析问题b):如果所有哲学家都设法在同一时间点获得一根筷子,那么所有哲学家要么是左撇子,要么都是右撇子。
因为这样就没有筷子的斗争,每个哲学家都拿着一根筷子。
但这违反了你的前提条件:至少一位左撇子和一位右撇子哲学家。
假设除了一个人都是右撇子,两个哲学家将争夺一根筷子。这场斗争将失败,将无法拿起筷子。因此,条件 "all pick up a chopstick simultaneously" 无法满足。正如您正确陈述的那样,蕴涵的前提条件为假,因此,蕴涵的计算结果为真。
所以回答你的问题:是的,你的推理是正确的。
Lemma 1: we know at any table with a mixture of left-handed and right-handed philosophers, deadlock cannot occur. I very familiar with it proofs.
我 运行 最近在采访中遇到了以下问题。
有 5 位哲学家围坐在一起 table。每两个哲学家之间有一根筷子。每个哲学家需要两根筷子吃饭。我们有两种类型的哲学家:左撇子和右撇子。左撇子先用左手拿筷子。右撇子先用右手拿筷子。假设 5 位哲学家中至少有 1 位左撇子和至少 1 位右撇子。哪一个是正确的:
a) independent from the combination of placement philosophers at round table, there is no deadlock. (I sure True)
b) if all of the philosophers simultaneously take the first chopsticks, there is a deadlock. (I thin this is true because in implication if we have a-->b and a is false a-->b is true., and in this option there is no way to all philosopher simultaneously take the first chopsticks, so the whole statement is true.)
哪位高手可以帮帮我,我的论点是真的吗?
Edit 1: I add the proof for Lemma1: (but the question mentioned above has some differences. )
First observe that due to the pattern of resource acquisition around the table there is only one possible wait-cycle, i.e., the cycle involving all philosophers. So assume such a deadlock. Every philosopher must be waiting, by which we mean waiting for a chopstock held by another. Thus all chopsticks must be held. If our table has a mixture of left-handed and right-handed philosophers, there must be at least one pair of adjacent philosophers of opposite handedness. First assume a left-handed philosopher (“Lenny”) seated to the left of a right-handed philosopher (“Roger”). Because all chopsticks must be held, either Lenny or Roger must hold the chopstick which is between them. If Lenny holds it, that is his “right chopstick,” so he must previously have acquired the chopstick to his left. Thus Lenny holds two chopsticks, and is not waiting to acquire any (he is eating), so there is not a deadlock. If Roger holds the chopstick which is between them, that is his “left chopstick,” so he must previously have acquired the chopstock to his right, etc. If we call the previous case the “outward reaching” case, then the “inward reaching” case is a right-handed philosopher seated to the left of a left-handed philosopher. Again, if we have a deadlock, all chopsticks must be held, so one of them holds the chopstick between them. This means that the other one holds no chopsticks, since the one between them is the first one each will try to acquire (either Roger reached right and got it, or Lenny reached left and got it; the other is waiting for it before reaching in the outward direction). If there are n philosphers and n chopsticks, all chopsticks held, but one philosopher holds zero chopsticks, then n−1 philosophers hold n chopsticks. Some philospher must hold two chopsticks; that philosopher is not waiting (he is eating), so there is no deadlock.
这里有一个例子:
一位左撇子哲学家,四位右撇子哲学家: 如果所有人都拿起一根筷子,左撇子哲学家赢得了对他左手边筷子的争夺,他有一根筷子,而他右手边的一根仍然是空闲的。在下一次迭代中,他或他右手边的邻居将拿起最后一根空闲的筷子。无论哪种方式,至少有一位哲学家有两根筷子吃饭。 --> 没有死锁
假设没有哲学家试图拿起 "outward" 筷子,除非他已经拿到 "inward" 一根。
现在我们来剖析问题b):如果所有哲学家都设法在同一时间点获得一根筷子,那么所有哲学家要么是左撇子,要么都是右撇子。 因为这样就没有筷子的斗争,每个哲学家都拿着一根筷子。 但这违反了你的前提条件:至少一位左撇子和一位右撇子哲学家。
假设除了一个人都是右撇子,两个哲学家将争夺一根筷子。这场斗争将失败,将无法拿起筷子。因此,条件 "all pick up a chopstick simultaneously" 无法满足。正如您正确陈述的那样,蕴涵的前提条件为假,因此,蕴涵的计算结果为真。
所以回答你的问题:是的,你的推理是正确的。