4

I recently encountered the bakery algorithm in my studies and just need to clarify some things.

  1. 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?

  2. Is setting number[i] to zero after the critical section important for success in the absence of contention?

  3. 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.

Kyle
  • 69
  • 6

1 Answers1

1

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?

It wouldn't violate mut. ex. as long as two or more different processes don't have the same number. But it would violate fairness since a process which later came to the critical section would be given precedence to enter it over some other process which has been waiting for more time. So, it's not critical, but it's also not ideal.

Is setting number[i] to zero after the critical section important for success in the absence of contention?

I don't think it's important. That reset serves the purpose to indicate that a process no longer wishes to enter the critical section. Not resetting its value may cause others to think the process wishes to enter the critical section, which may not be good, but I don't see it linked to a performance issue.

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.

I thought it certainly was, until I read that "as that isn't the correct reason for it." If you could share some more knowledge on this third point, I'd be thankful!

89f3a1c
  • 1,430
  • 1
  • 14
  • 24