Question: Consider the following program executed by two different threads P1 and P2: shared int x; x = 10; while (1) //s1 //s2 x=x-1; x=x+1; if

 Consider the following program executed by two different threads P1 and

Consider the following program executed by two different threads P1 and P2: shared int x; x = 10; while (1) //s1 //s2 x=x-1; x=x+1; if (x != 10) //s3 //s4 //s5 //s6 printf("X is %d" , x) Consider that the threads P1 and P2 are executed on a uniprocessor system. Note that the scheduler in a uniprocessor system would implement pseudoparallel execution of these two concurrent threads by interleaving their instructions, without restriction on the order of the interleaving a. Show a sequence (i.e., trace the sequence of interleavings of statements) such that the statement "x is 10" is printed. Suggested format: b. Show a sequence that leads to the statement "x is 8" be printed. Hint: Remember that the increment/decrements at the source language level are not done Pi: atomically, e.g., the assembly language code below implements the single C increment instruction (x = x + 1) LD RO, X / load into register RO from memory location x */ INCR RO / increment value stored in RO*/ STO RO,x /* store the incremented value back in X */ Consider the following program executed by two different threads P1 and P2: shared int x; x = 10; while (1) //s1 //s2 x=x-1; x=x+1; if (x != 10) //s3 //s4 //s5 //s6 printf("X is %d" , x) Consider that the threads P1 and P2 are executed on a uniprocessor system. Note that the scheduler in a uniprocessor system would implement pseudoparallel execution of these two concurrent threads by interleaving their instructions, without restriction on the order of the interleaving a. Show a sequence (i.e., trace the sequence of interleavings of statements) such that the statement "x is 10" is printed. Suggested format: b. Show a sequence that leads to the statement "x is 8" be printed. Hint: Remember that the increment/decrements at the source language level are not done Pi: atomically, e.g., the assembly language code below implements the single C increment instruction (x = x + 1) LD RO, X / load into register RO from memory location x */ INCR RO / increment value stored in RO*/ STO RO,x /* store the incremented value back in X */

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!