22 votes 22 votes Consider the concurrent program x := 1; cobegin x := x + x + 1 || x := x + 2 coend; Reading and writing of a variable is atomic, but evaluation of an expression is not atomic. The set of possible values of variable $x$ at the end of execution of the program is $\left\{3\right\}$ $\left\{7\right\}$ $\left\{3, 5, 7\right\}$ $\left\{3, 7\right\}$ $\left\{3, 5\right\}$ Operating System tifr2012 process-synchronization operating-system + – makhdoom ghaya asked Oct 31, 2015 • edited Jun 17, 2018 by kenzou makhdoom ghaya 2.2k views answer comment Share Follow See 1 comment See all 1 1 comment reply Ashwani Kumar 2 commented Aug 30, 2019 reply Follow Share Repeated question: https://gateoverflow.in/18751/tifr2010-b-28 0 votes 0 votes Please log in or register to add a comment.
Best answer 18 votes 18 votes $1. x = 1$, Run $x = x + 2$ then $x= x + x + 1$ finally $x$ will be $7$. $2. x = 1$, run $x = x + 2$ and $x = x + x + 1$, parallely .. $x = 5 , 3$ Final answer would be $\{3, 5, 7\}$ Digvijay Pandey answered Oct 31, 2015 • edited Jun 17, 2018 by kenzou Digvijay Pandey comment Share Follow See all 10 Comments See all 10 10 Comments reply shraddha priya commented Aug 10, 2017 i edited by shraddha priya Aug 20, 2017 reply Follow Share @bikram sir I didn't get how this expression gets evaluated. Doesn't short circuit work here? If there is a || then why calculate expressions on both sides of the OR if one side is already TRUE? Please help. 0 votes 0 votes AnilGoudar commented Aug 18, 2017 reply Follow Share @Arjun Sir, a || b :- if a is TRUE, b will not treated for evaluation , since a is x=x+x+1 in the question which is always true, hence second expression will not be evaluated in which final answer is the result of x=x+x+1, in which x can take only one value {3}. Please help me to understand. Getting confused here. 0 votes 0 votes Bikram commented Aug 20, 2017 reply Follow Share @ AnilGoudar and @ shraddha priya This is sequential part : x := x + x + 1 || x := x + 2 x =1( initial value ) First run x = x+2 , x value become 3 Now x=3, run x = x + x + 1 , x value will be 3+3+1=7 here we get { 7 } ------------------ This is parallel part: initialized value of x =1 x= x+2 = 1+2 = 3 x=x+x+1= 1+1+1 = 3 Both will take x as 1 initially . Both will run independently . But final write done by process x=x+x+1 It will give result 3. x=x+x+1 completed its execution before x=x+2. Then x= x+2 will read value of x as 3 and then x=x+2 i.e. x= 3+2 = 5 so here we get { 3,5 } Final answer is combination of both sequential and parallel part : which is { 3,5,7 } , option C . 24 votes 24 votes AnilGoudar commented Aug 21, 2017 reply Follow Share Thank You Sir, got it now 0 votes 0 votes shraddha priya commented Aug 21, 2017 reply Follow Share @Bikram sir, why doesn't the short circuit concept apply here? 0 votes 0 votes Bikram commented Aug 21, 2017 reply Follow Share Because of co begin : co end just check how co begin and co end works .. i don't think they are in current GATE syllabus though. 13 votes 13 votes set2018 commented Nov 17, 2017 reply Follow Share The cobegin and coend primitives, originally called parbegin and parend , specify a set of program segments that may be executed concurrently http://www.ics.uci.edu/~bic/os/OS/PROOFS/bicc02v2.pdf 1 votes 1 votes talha hashim commented Apr 27, 2018 reply Follow Share nice explanation @Bikaram sir u remove all the doubts 0 votes 0 votes `JEET commented Dec 5, 2019 reply Follow Share Bikram Sir's comment should become the answer. 0 votes 0 votes Chinmay Agnihotri commented Jul 7, 2020 reply Follow Share Since it is given that the evaluation of an expression is not atomic, can 4 be an answer as well? (Although not mentioned in options) While evaluating the first expression x = x+x+1, if after evaluation of x=x+x, resulting in value of x equal to 2, can the process preempt to the other condition , i.e x= x+2, to give the value 4? 0 votes 0 votes Please log in or register to add a comment.