Take the 2-minute tour ×

given the lamport's fast mutex algorithm, i'm trying to understand why are the awaits there.

The algorithm:

start: b[i] = true
      x = i 
      if y != 0 then b[i] = false
                          await y = 0
                          goto start 
      y = i
      if x != i then b[i] = false
                         for j = 1 to n do await b[j] = false od
                         if y != i then await y = 0
                                            goto start 
      critical section
      y = 0
      b[i] = false 

Can't we just remove both of them?

share|improve this question
add comment

1 Answer

You want to wait (block) instead of spin (continually execute checking for availability) while the other process/thread is in the critical section, otherwise you're taking up resources that could be used elsewhere. If only one thread can run at a time, then you would prevent the thread in the critical section from running during your entire timeslice resulting in the program taking much longer to complete.

share|improve this answer
Sorry, this is not exactly what i ment, what i wanted to ask is, what will happen if for example i'll remove the await y=0 from if y != i then await y = 0 –  MindFold Nov 14 '10 at 9:55
@MindFold - then you'll spin, i.e., rapidly continue checking the guard variables consuming resources that could otherwise go to another thread/process including the one in the critical section, instead of block, allowing other threads/processes to proceed. –  tvanfosson Nov 14 '10 at 12:58
add comment

Your Answer


