1

I'm doing an 'operating systems' topic and I can't get my head around this:

We have been asked to demonstrate how mutual exclusion can be violated if wait(s) is not handled atomically. (semaphore implementation)

Now, I see how this may cause an incorrect count, resulting in the program thinking it has more resources available than it truly does,

But I can't seem to grasp the concept of how this will violate mutual exclusion :(

Can anyone shed some light or point me in the right direction?

Peter
  • 11
  • 3

2 Answers2

0

Let us assume that below is the code for wait(S)(example of galvin)

 wait(S) {
         while (S <= 0 )
         ; // busy wait
         S--;
}

If the wait(S) operation is not atomic i.e all operation inside wait(S) are not executed all at once.Two thread T1 and T2 are executing the same operation wait(S) simultaneously since the wait(S) operation is not atomic and T1 updates the value of S and at the same time T2 updates(overwrite the value written by T1) the actual decrement in the value of S is 2 but the simultaneously execution causes decrement in only 1 This scenario is known as race condition and this causes an incorrect count, resulting in the program thinking it has more resources available than it truly does.you can read more about race condition here http://en.wikipedia.org/wiki/Race_condition

akashchandrakar
  • 2,009
  • 3
  • 23
  • 47
0

Number two result on Google (this question was number one): http://web.cs.wpi.edu/~cs502/f98/Waltham/hw2soln.html

See question 2.

jfGit
  • 1
  • 1
    Known fact: Google may show different results for different people and/or different computers and/or different browsers. – sjngm Sep 01 '11 at 05:28