Google Answers Logo
View Question
 
Q: Operating Systems- Process Synchronization ( Answered,   0 Comments )
Question  
Subject: Operating Systems- Process Synchronization
Category: Computers > Algorithms
Asked by: rabcak-ga
List Price: $5.00
Posted: 23 Nov 2002 11:15 PST
Expires: 23 Dec 2002 11:15 PST
Question ID: 113258
Show that, if the wait and signal operations are not executed
atomically, then mutual exclusion may be violated.
Answer  
Subject: Re: Operating Systems- Process Synchronization
Answered By: theta-ga on 25 Nov 2002 11:57 PST
 
Lets say that the Wait and Signal operations are implemented as shown
in the pseudocode given below :

Wait (Semaphore S)
   while (S.count <= 0)
     {// Loop as long as S.count <= 0}
   S.count = S.count - 1

Signal (Semaphore S)
  S.count = S.count + 1

Assume that the semaphore is initialized with count 1.
Let there be two processes ( P1 & P2 excecuting). Then, as per the
timeline given below, mutual exclusion will be violated.
Time  Events
----  ------
T0  : S.count = 1. P1 calls Wait, executes the while loop, and breaks
out because count is positive. Then a context switch occurs to T2
before T1 can decrement count.
T1  : S.count = 1. P2 calls Wait, executes the while loop, decrements
count, and returns and enters the critical section. Then a context
switch occurs to T1.
T2  : S.count = 0. P1 decrements count, and also enters the critical
section.

At time T2, both the processes T1 and T2 are in the critical section
and the mutual exclusion is therefore violated as a result of a lack
of atomicity

Hope this helps.
If you need any clarifications, just ask!
:)
Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy