Example 1 What is the value at line A B 2 What if we add a line exec before

# Example 1 what is the value at line a b 2 what if we

• Test Prep
• 14

This preview shows page 11 - 14 out of 14 pages.

Example 1.What is the value at line A, B?2.What if we add a line “exec();” before “value+=15;”. Answer question 1 again. 3. Describe the state transition of parent process /* Line A */ /* Line B */
5.12 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Example 1. 20 and 5 2. 5 and 5 3.
5.13 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Example The first known correct software solution to the critical-section problem was developed by Dekker. The two processes, P0 and P1, share the following variables: boolean flag; /* initially false */ and int turn; The structure of process Pi (i== 0 or 1) is shown in Figure. The other process is Pj (j== 1 or 0).1.Explain how this solution ensures mutual exclusion.2.What is the major limitation of this solution?3.What is a possible remedy to this limitation?
5.14 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Example If process j is in critical section (flag[j]==true && turn==j), process i will stay busy waiting. Once process j completes the critical section, it will set turn=i and flag[j]=false. Then process i can jump out of the busy waiting loop since turn!=j. Then process i will set flag[i]=true, thus again ensuring mutual exclusion. It can only work for 2 processes. To support multiple processes, a counting semaphore can be used. Definition of the wait() operation wait(S) { while (S <= 0) ; // busy wait S--; } Definition of the signal() operation signal(S) { S++; }
• • • 