but it says "**at the end of execution of the program**". try to evaluate in any order, we will get only one value for X i.e x=4.

**option A** should be the answer.

The Gateway to Computer Science Excellence

+10 votes

Consider the following concurrent program (where statements separated by | | with-in cobegin-coend are executed concurrently).

x:=1 cobegin x:= x + 1 || x:= x + 1 || x:= x + 1 coend

Reading and writing of variables is atomic but evaluation of expressions is not atomic. The set of possible values of $x$ at the end of execution of the program is

- $\left \{ 4 \right \}$
- $\left \{ 2, 3, 4 \right \}$
- $\left \{2, 4 \right \}$
- $\left \{ 2, 3 \right \}$
- $\left \{2 \right \}$

+11 votes

Best answer

0

but it says "**at the end of execution of the program**". try to evaluate in any order, we will get only one value for X i.e x=4.

**option A** should be the answer.

+1

2,3,4 is correct ..

i numbered all exp 1, 2, 3

i am executing like 1 2 3 it will give 4 ,

if evaluating all concurrent means all expression read x=1 and evulate same time it will give 2 as op..

now if i do like evaluate exp1 which give 2 then 2 exp in which i read only x value which is 2 and preempt this and evaluate exp 3 which also take x as2 and after executing x=3 , now i came back to exp 2 which was preempted it simmply add 1 to x=2(which is already read so it will not take new value ) and give op as x=3 so , 2 3 4 as op possible

i numbered all exp 1, 2, 3

i am executing like 1 2 3 it will give 4 ,

if evaluating all concurrent means all expression read x=1 and evulate same time it will give 2 as op..

now if i do like evaluate exp1 which give 2 then 2 exp in which i read only x value which is 2 and preempt this and evaluate exp 3 which also take x as2 and after executing x=3 , now i came back to exp 2 which was preempted it simmply add 1 to x=2(which is already read so it will not take new value ) and give op as x=3 so , 2 3 4 as op possible

0

see the Bikram sir comment, he explain beautifully.

https://gateoverflow.in/25109/tifr2012-b-9

and see this also https://gateoverflow.in/18751/tifr2010-b-28

+3 votes

consider 1) x=x+1 , 2) x=x+1 , 3) x=x+1

case 1: - [ 1) reads x=1 ] preempts -> [ 2) reads x=1 ] preempts -> [ 3) reads x=1 and perform x+1 and stores in x now x = 2 ]

similarly [ 1) comes back performs x+1 and stores x now x=2] , for [ 2) also performs x+1 stores x now x=2]

value of x for [ 1) is 2 ] , [ 2) is 2 ] , [ 3) is 2] = = {2}

case 2:- [ 1) reads x=1 perform x+1 stores in x now x = 2] , [ 2) reads x=2 ] preempts -> [ 3) reads x=2 and perform x+1 and stores x=3]

similarly [ 2) comes back and perform x+1 stores x=3]

value of x for [ 1) is 2] , [ 2) is 3 ], [ 3) is 3] == {2, 3}

case 3:- no one preempts [ 1) reads x= 1 and perform x+1 and stores x now x=2], [2 reads x=2 and perform x+1 and stores x now x =3], [ 3) reads x = 3 and perform x+1 and now x=4]

value of x for [ 1) is 2], [ 2) is 3], [ 3) is 4] == {2,3,4}

question is asked for possible values since possible values are {2}, {2,3}, {2,3,4}

but {2,3,4 } is only option which includes {2} as well as {2,3}

option is b) correct answer

case 1: - [ 1) reads x=1 ] preempts -> [ 2) reads x=1 ] preempts -> [ 3) reads x=1 and perform x+1 and stores in x now x = 2 ]

similarly [ 1) comes back performs x+1 and stores x now x=2] , for [ 2) also performs x+1 stores x now x=2]

value of x for [ 1) is 2 ] , [ 2) is 2 ] , [ 3) is 2] = = {2}

case 2:- [ 1) reads x=1 perform x+1 stores in x now x = 2] , [ 2) reads x=2 ] preempts -> [ 3) reads x=2 and perform x+1 and stores x=3]

similarly [ 2) comes back and perform x+1 stores x=3]

value of x for [ 1) is 2] , [ 2) is 3 ], [ 3) is 3] == {2, 3}

case 3:- no one preempts [ 1) reads x= 1 and perform x+1 and stores x now x=2], [2 reads x=2 and perform x+1 and stores x now x =3], [ 3) reads x = 3 and perform x+1 and now x=4]

value of x for [ 1) is 2], [ 2) is 3], [ 3) is 4] == {2,3,4}

question is asked for possible values since possible values are {2}, {2,3}, {2,3,4}

but {2,3,4 } is only option which includes {2} as well as {2,3}

option is b) correct answer

+1 vote

we can do this, in this way also -

(1) first run all three parallely so we get x= 2

(2) first run first statement(x=1+1=2) then second (x=2+1=3)then third so finally x=3+1=4

(3)first run any of two parallely so x will become x=2 then run third statement now x =2+1=3

{2,3,4} possible values of x.

(1) first run all three parallely so we get x= 2

(2) first run first statement(x=1+1=2) then second (x=2+1=3)then third so finally x=3+1=4

(3)first run any of two parallely so x will become x=2 then run third statement now x =2+1=3

{2,3,4} possible values of x.

- All categories
- General Aptitude 1.9k
- Engineering Mathematics 7.5k
- Digital Logic 2.9k
- Programming and DS 4.9k
- Algorithms 4.4k
- Theory of Computation 6.2k
- Compiler Design 2.1k
- Databases 4.1k
- CO and Architecture 3.4k
- Computer Networks 4.2k
- Non GATE 1.4k
- Others 1.4k
- Admissions 595
- Exam Queries 573
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 18

50,737 questions

57,355 answers

198,482 comments

105,249 users