Skip to main content

Consider the following program P1 P2 shared int x shared int x x

  1. New Jersey Institute of Technology
  2. Operating Systems Design
  3. Question
Student

nithin krishna

Subject:Computer Science

Consider the following program:

 

  P1: {                                    P2: {

 shared int x;                                   shared int x;

x = 10;                                                x = 10;

while (1) {                                                        while ( 1 ) {

   x = x - 1;                                            x = x - 1;

   x = x + 1;                                            x = x + 1;

   if (x != 10)                                                       if (x!=10)

    printf(“x is %d”,x)                                                     printf(“x is %d”,x)

    }                                                                                    }

  }                                                                       }

Note the scheduler in a uniprocessor system would implement pseudo-parallel execution of these two concurrent processes by interleaving their instructions, without restriction on the order of the interleaving.

 

Show a sequence (i.e., trace the sequence of interleavings of statements) such that the statement “x is 10” is printed.

LikeLike
0

AnswerCreated with AI

Answer The program you've provided is a classic example of a race condition, where two or more threads are accessing and manipulating the same shared data concurrently. The final


Related Answered Questions