0% found this document useful (0 votes)
7 views11 pages

OS Lecture 16 - Process Syncronization - Examples

The document discusses process synchronization in computing, providing examples of methods used by processes to access critical sections and the implications of these methods on mutual exclusion and progress. It includes scenarios involving semaphores and concurrent processes, analyzing the outcomes of various synchronization constructs. Additionally, it poses questions related to the behavior of processes and the resulting values of shared variables after execution.

Uploaded by

whoarey196
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views11 pages

OS Lecture 16 - Process Syncronization - Examples

The document discusses process synchronization in computing, providing examples of methods used by processes to access critical sections and the implications of these methods on mutual exclusion and progress. It includes scenarios involving semaphores and concurrent processes, analyzing the outcomes of various synchronization constructs. Additionally, it poses questions related to the behavior of processes and the resulting values of shared variables after execution.

Uploaded by

whoarey196
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

‫ہللا َّالر ٰمح ِن َّالرحميِ‬

‫بِس ِم ِ‬
‫ح‬ ‫ج‬ ‫ُ‬ ‫ٰ‬ ‫ل‬
‫ال َلہتعا ی کے پاکپام سےشروع وبڑامہرپان ہايتر موالا ہے۔‬
‫ن‬

‫‪1‬‬
Process Synchronization

2
Process Synchronization

3
Process Synchronization – Example 2
❑ Consider the methods used by processes P1 and P2 for accessing their
critical sections whenever needed, as given below. The initial values of
shared Boolean variables S1 and S2 are randomly assigned.
Method used by P1 Method used by P2
while (S1 == S2) ; while (S1 != S2) ;
Critical Section Critical Section
S1 = S2; S2 = NOT(S1);

❑ Which one of the following statements describes the properties


achieved?
a) Mutual exclusion but not progress
b) Progress but not mutual exclusion
c) Neither mutual exclusion nor progress
d) Both mutual exclusion and progress
4
Process Synchronization – Example 2
❑ The following program consists of 3 concurrent processes and 3 binary
semaphores. The semaphores are initialized as S0=1, S1=0, S2=0.
Process P0 Process P1 Process P2
while(true) { wait (S1); wait (S2);
wait (S0); Signal (S0); Signal (S0);
print (O);
Signal (S1);
Signal (S2);
}

❑ How many times will process PO print '0' ?


(a) At least twice (Correct)
(b) Exactly thrice
(b) Exactly twice
(d) Exactly once
❑ Reason: If P0, P1, P2, P1 executed in an order '0’ will be printed two times and If P0, P1, P0, P2 executed in
an order '0’ will be printed three times. So, At least twice '0’ will be printed by P0. 5
Process Synchronization

❑ Two processes, P1 and P2, need to access a critical section of code.


Consider the following synchronization construct used by the
processes:
Process P0 Process P1
while (true) { while (true) {
S = true; Q = true;
while (Q == true); while (S == true);
/ * Critical Section */ / * Critical Section */
S = false; Q = false;
} }
/* Remainder section */ /* Remainder section */

6
Process Synchronization

❑ Here, wants1 and wants2 are shared variables, which are initialized to
false. Which one of the following statements is TRUE about the above
construct?
(a) It does not ensure mutual exclusion.
(b) It does not ensure bounded waiting.
(c) It requires that processes enter the critical section in strict
alternation.
(d) It does not prevent deadlocks, but ensures mutual exclusion.
7
Process Synchronization

❑ Consider three concurrent processes Pl, P2 and P3 as shown below,


which access a shared variable D that has been initialized to 100.
P1 P2 P3
. . .
. . .
D = D + 20 D = D – 50 D = D + 10
. . .
. . .

❑ The process are executed on a uniprocessor system running a time-


shared operating system. If the minimum and maximum possible
values of D after the three processes have completed execution are X
and Y respectively, then the value of Y-X is
(a) 80 (b) 130 (c) 50 (d) None of these
8
Process Synchronization

❑ A counting semaphore was initialized to 10. Then 6 P (wait) operations


and 4V (signal) operations were completed on this semaphore. The
resulting value of the semaphore is
❑ (a) 0
❑ (b) 8
❑ (c) 10
❑ (d) 12

9
Process Synchronization
❑ Suppose we want to synchronize two concurrent processes P and Q using binary
semaphores S and T. The code for the processes P and Q is shown below-
Process P Process Q
while(1) { while(1) {
w: Y:
print ‘0’; print ‘1’;
print ‘0’, print ‘1’,
x: Z:
} }

❑ Synchronization statements can be inserted only at points W, X, Y and Z. Which


sequence lead to an output string with ‘001100110011'?

Solution: P(s) at W, v(T) at X, P(T) at Y, V(S) at Z, S initially 1 and T initially 0


10
JAZAK ALLAH!
Any Question?

11

You might also like