我最近在学习中遇到了面包店算法,只需要澄清一些事情。
最佳答案
Would it be possible for the bakery algorithm to violate mutual exclusion if processes did not pick a ticket number larger than that of all existing tickets?
它不会违反 mut。前任。只要两个或多个不同的进程没有相同的编号。但这会违反公平性,因为稍后进入临界区的进程将优先进入它,而不是等待更多时间的其他进程。因此,这并不重要,但也不理想。
Is setting number[i] to zero after the critical section important for success in the absence of contention?
我不认为这很重要。该重置用于指示进程不再希望进入临界区。不重置其值可能会导致其他人认为该进程希望进入临界区,这可能不太好,但我认为它与性能问题无关。
And is one of the reasons for the bakery algorithm not being used in practice because the process of finding the maximum value of an array is non-atomic? I thought this was not the case, as that isn't the correct reason for it.
我认为肯定是这样,直到我读到“因为这不是正确的理由”。如果您能分享更多关于第三点的知识,我将不胜感激!
关于algorithm - 关于 Bakery 算法的一些一般问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42514162/