Awesome q2a theme
0 votes
18 views

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.

 

 

 

 

in Operating System by (13 points) | 18 views
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
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.
0
Thanks

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
8,437 questions
2,714 answers
13,238 comments
95,460 users