Question

In: Computer Science

Operating system : Concurrent processes P0 and P1 use the following C-codes to access a critical...

Operating system :
Concurrent processes P0 and P1 use the following C-codes to access a critical section CS:

Void p0() / / process P0

{

while (TURE){

Flag[0]=TURE; turn=1;

While (flag[1]&&(turn==1))

Critical section;

Flag[0]=FALSE;

} }


Void p1() / / process P1

{

while (TURE){

Flag[1]=TURE; turn=0;

While (flag[0]&&(turn==0))

Critical Section (CS);

Flag[1]=FALSE;

} }

where the initial values for the shared variables are:

boolean flag[2] ;

int turn=0;

flag[0]=false; flag[1]=false;


The above implementation of P0 and P1 guarantees ()


A) both mutual exclusion for CS access and bounded-waiting for entry to CS

B) neither mutual exclusion for CS access, nor bounded-waiting (non-starvation) for entry to CS

C) mutual exclusion for CS access, but not bounded-waiting for entry to CS

D) bounded-waiting for entry to CS, but not mutual exclusion for CS access



please provide explanation for your answer.

please only answer id you are sure of the answer thank you.

Solutions

Expert Solution

Answer:Option (A) - both mutual exclusion for CS access and bounded-waiting for entry to CS

Explanation:
Here we have two shared variables:

  • boolean flag[2], which represents whether a process is interested to go into the critical section or not.
  • int turn determines the process whose turn is to enter the critical section.

When a process wants to execute its critical section, it sets its flag = true and turn as the index of the other process. This means that the process wants to execute but it will allow the other process to run first. The process performs busy waiting until the other process has finished its own critical section. If the process desires to acquire the critical section, then, it gets the critical section and passes the chance to the 2nd process. If it does not desire to get the critical section then the while loop breaks and the 1st process gets the chance.

Busy Waiting.
Flag[0]=TRUE; turn=1;
While (flag[1] && (turn==1));
// P1_gate

P0 and P1 can never be in the critical section at the same time (MUTUAL EXCLUSION): If P0 is in its critical section, then flag[0] is true. In addition, either flag[1] is false (meaning P1 has left its critical section), or turn is 0 (meaning P1 is just now trying to enter the critical section, but graciously waiting), or P1 is at the label P1_gate (trying to enter its critical section, after setting flag[1] to true but before setting turn to 0 and busy waiting). So if both processes are in their critical sections then we conclude that the state must satisfy flag[0] and flag[1] and turn = 0 and turn = 1. No state can satisfy both turn = 0 and turn = 1, so there can be no state where both processes are in their critical sections.

Bounded waiting says that a bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted.

Here, the Peterson's solution is considered strict alternation so, alternatively, process[0] and process[1] will get access to the critical section. Here bounded waiting won't be satisfied in case e.g. some process gets C.S. repeatedly starving other processes but this situation is not possible because of a strict alternation.

By using 'turn' variable bounded waiting is ensured.

Note:If you have any doubts or queries please comment I willget back to you and clarify.


Related Solutions

Operating system : Concurrent processes P0 and P1 use the following C-codes to access a critical...
Operating system : Concurrent processes P0 and P1 use the following C-codes to access a critical section CS: Void p0() / / process P0 { while (TURE){ Flag[0]=TURE; turn=1; While (flag[1]&&(turn==1)) Critical section; Flag[0]=FALSE; } } Void p1() / / process P1 { while (TURE){ Flag[1]=TURE; turn=0; While (flag[0]&&(turn==0)) Critical Section (CS); Flag[1]=FALSE; } } where the initial values for the shared variables are: boolean flag[2] ; int turn=0; flag[0]=false; flag[1]=false; The above implementation of P0 and P1 guarantees ()...
Deadlock –Banker’s Algorithm A system has three resource types (A, B, C) and four processes {P1,...
Deadlock –Banker’s Algorithm A system has three resource types (A, B, C) and four processes {P1, P2, P3, P4 }. The total units of system resources are: (8, 5, 4) units of A, B and C, respectively. The maximum demands for each process is P1(1,2,3), P2(3,2,1), P3(6,5,4) and P4(4,4,2). The current allocation is: P1(0,1,1), P2(2,2,0) and P3(3,0,1) and P4(1,0,1). (a) Allocation table is given for the 3 processes with the following four columns: PROCESS, ALLOCATION, MAX and NEED. And fill...
If a firm is facing an exogenously given price, P0, and industry conditions change such that the new market price is P1 > P0, which of the following is true?
1 If a firm is facing an exogenously given price, P0, and industry conditions change such that the new market price is P1 > P0, which of the following is true?a. None of the other options are correct.b. The total revenue curve will become steeper, with an increase in slope on the graph, with dollars on the vertical axis and firm quantity on the horizontal axis.c. The total revenue curve will reach its maximum at a new, higher output than under...
urgent please, in operating system: One simple method to protect a critical section is to use...
urgent please, in operating system: One simple method to protect a critical section is to use mutex locks, also called spinlocks. An alternative method would be use a binary semaphore initialized to 1, with the implementation that uses busy waiting. Is there any real difference between these two methods? Explain.
1. If a firm is facing an exogenously given price, P0, and industry conditions change such that the new market price is P1 > P0, which of the following is true?
 1: If a firm is facing an exogenously given price, P0, and industry conditions change such that the new market price is P1 > P0, which of the following is true?a. None of the other options are correct.b. The total revenue curve will become steeper, with an increase in slope on the graph, with dollars on the vertical axis and firm quantity on the horizontal axis.c. The total revenue curve will reach its maximum at a new, higher output than...
If there are 32 concurrent processes, how will you modify the following code? Process i do...
If there are 32 concurrent processes, how will you modify the following code? Process i do { while (turn == j);                critical section; turn = j;                remainder section } while (true);
Assuming that there are 9 processes in a distributed system numbered p1, p2, ..., p9. Describe...
Assuming that there are 9 processes in a distributed system numbered p1, p2, ..., p9. Describe a situation where deadlock may occur when using Maekawa’s algorithm in this system.
Consider an index consisting of the following stocks: P0 P1 shares (m) ABC 90 100 10...
Consider an index consisting of the following stocks: P0 P1 shares (m) ABC 90 100 10 CBA 50 35 20 Calculate the value-weighted return on the index! -9.44% -10.53% -3.57% 11.54%
. Explain in detail the two types of processes in an operating system and explain the...
. Explain in detail the two types of processes in an operating system and explain the advantages of them.
How to use or embed assembly routines/codes in C programs?
How to use or embed assembly routines/codes in C programs?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT