746 views
1 votes
1 votes
Consider the program segment:
x= 0; y=0;
Cobegin
begin
x= 1;
y= y + x;
end
begin
y= 2;
x= x + 3;
end
Coend;
Which of the following indicates possible values for the variables when the segment finishes
execution????

 

WHAT HAPPENS IF IN PLACE OF COEND AND COBEGIN  THERE IS PAR BEGIN AND PAREND???

PLEASE EXPLAIN THIS IN DETAIL AND I AM NOT ABLE TO FIND THIS TOPIC ALSO HELP IN WHICH TOPIC THESE CONCEPTS ARE INCLUDED

2 Answers

Best answer
4 votes
4 votes

The Basics:-

As per your question:-

just name them

1. x=1

2. y = y+x

3. y=2

4. x=x+3

 

let A:       begin: 1,2, end

let B:       begin: 3,4, end

 

Finally your question is

Co-begin:

        A

        B

Co-end:

 

How many orders possible? ( just go with the formula in DBMS, Concurrent Transaction )

total order = $\frac{(2+2)!}{2! . 2!} = \frac{(4)!}{4} = 6 $

what are they:-

(i) 1,2,3,4

(ii) 1,3,2,4

(iii) 1,3,4,2

(iv) 3,4,1,2

(v) 3,1,4,2

(vi) 3,1,2,4

 

DBMS vs OS :-

in DBMS, these (1,2,3,4) are transactions, those are atomic operations in a Transactions

but in Os, these(1,2,3,4) are instructions, those are atomic or non-atomic

 

What are the possibilities of output if those are atomic instructions?

Directly, you can execute every order.

(i) 1,2,3,4  ===> lead to final output : x= 4,  y=2

(ii) 1,3,2,4  ===> lead to final output : x= 4,  y=3

(iii) 1,3,4,2  ===> lead to final output : x= 4,  y=6

(iv) 3,4,1,2  ===> lead to final output : x= 1,  y=3

(v) 3,1,4,2  ===> lead to final output : x= 4,  y=6

(vi) 3,1,2,4  ===> lead to final output : x= 4,  y=3

 

What are the possibilities of output if those are non-atomic instructions ?

you have think the instruction is like ( load, increment, store )

 all the 6 possibilities also in this output, along with

x=4,y=1 when 1,2(load,increment,preempt),3,4,2(store)

x=3,y=5 when 2,4(load,store,preempt),1,4(store),2

x=3,y=3 when 2,4(load,store,preempt),1,2,4(store)

x=3,y=3 when 2,4(load,store,preempt),1,2,4(store)

(i hope i covered all possibilities, if you found more comment)

edited by
1 votes
1 votes
first of all cobegin and par begin they both are same both indicates parallel operations

and begin and end indicates serial operations.

here we have 2 parallel operations if we number the operations of given process

4->8->9->5->6->10->11

after execution max value of x and y

x =4

y=6

No related questions found