bro consider the operations

x=y+1;

LD y

ADD #1

STORE x;

x=x+1;

LD x

ADD #1

as non atomic you will get the answer

x=y+1;

LD y

ADD #1

STORE x;

x=x+1;

LD x

ADD #1

as non atomic you will get the answer

Awesome q2a theme

0 votes

Consider the program given below using parbegin-parend.

Semaphore ml = 0, m = 1; integer x = 0, y = 23; parbegin begin V(ml); x = x + 1; p(m); end begin V(ml); x = y + 1; p(ml); end parend

What are final values of x?

Answer given is 1,24,25.

I am getting 24 but not 1 and 25.

Can someone please tell me how I can get 1 and 25.

0

bro consider the operations

x=y+1;

LD y

ADD #1

STORE x;

x=x+1;

LD x

ADD #1

as non atomic you will get the answer

x=y+1;

LD y

ADD #1

STORE x;

x=x+1;

LD x

ADD #1

as non atomic you will get the answer

0

So for getting 1. x will be incremented to 1 and then prempt right?

After that it will go to x = y + 1;

Here, it will also preempt and we will get 1 as the answer.

Is this calculation right?

+1

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

LD r2,y; LD r1,x;

r2=r2+1; r1=r1+1;

ST r2,x; ST r1,x;

now to get x=1:

perform all operation of x=y+1 but before storing prempt it and then perform all the operations of x=x+1 and before storing preempt it again. and now perform ST r2,x; and then ST r1,x; so the final storing value is from r1 so x will be updated to 1.

LD r2,y; LD r1,x;

r2=r2+1; r1=r1+1;

ST r2,x; ST r1,x;

now to get x=1:

perform all operation of x=y+1 but before storing prempt it and then perform all the operations of x=x+1 and before storing preempt it again. and now perform ST r2,x; and then ST r1,x; so the final storing value is from r1 so x will be updated to 1.

8,437 questions

2,714 answers

13,238 comments

95,460 users