Question: Consider the following program: Note that the scheduler in a uniprocessor system would implement pseudo parallel execution of these two concurrent processes by interleaving their

Consider the following program:

P1: P2: shared int x; x = 10; shared int x; x=10;


Note that 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.

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

b. Show a sequence such that the statement “x is 8” is printed. You should remember that the increment/decrements at the source language level are not done atomically, that is, the assembly language code:

while 1 while (1) ( x=x-1; x=x+1; if (x != 10) x=x-1;


Implements the single C increment instruction (x = x + 1).

P1: P2: shared int x; x = 10; shared int x; x=10; while 1 while (1) ( x=x-1; x=x+1; if (x != 10) x=x-1; x=x+1; if (x ! =10) printf("x is %d",x) printf ("X 18 %d", x) LD RO, x load RO from memory location x */ INCR RO* STO R0,X /*store the incremented value back in X */ increment RO /

Step by Step Solution

3.29 Rating (164 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a For x is 10 the interleaving producing the required behavior is easy to find since it requires onl... View full answer

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

Document Format (1 attachment)

Word file Icon

451-C-S-D-B-O-S (65).docx

120 KBs Word File

Students Have Also Explored These Related Operating System Questions!