16 16 votes Consider the following functions $f$ and $g$. f(){ x = x-50; y = y+50; } g( ) { a = a+x; a = a+y; } Suppose we start with initial values of $100$ for $x, 200$ for $y$, and $0$ for $a$, and then execute $f$ and $g$ in parallel - that is, at each step we either execute one statement from $f$ or one statement from $g$. Which of the following is not a possible final value of $a$? $300$ $250$ $350$ $200$ Operating System cmi2012 operating-system process-synchronization + – go_editor 2.2k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 11 11 votes Answer is (D) $200$ If we execute first $f()$ and then $g()$ then we get $300$ If we execute $1^{st}$ line of $g()$ , then $f()$ all the lines and then last line of $g()$ ,will get $350$ If we execute $1^{st}$ line of $f()$, then $1^{st}$ line of $g()$, then 2nd line of $g()$ and then $2^{nd}$ line of $f()$, we get $250$ srestha answered May 23, 2016 • edited Jun 29, 2018 by Milicevic3306 srestha comment Share Follow See all 6 Comments 6 6 Comments reply Show 3 previous comments Dileep kumar M 6 commented Nov 20, 2017 reply Follow flag if we execute g first a=a+x -> 100 a=a+y -> 100+200 = 300 then final value will be 300 not 200 0 0 replyShare mrinmoyh commented Sep 14, 2019 reply Follow flag there are $\frac{4!}{2! * 2!}$ ways we can execute these, right??? 2 2 replyShare rohith1001 commented Jan 6, 2020 reply Follow flag f(){ A) x = x-50; B) y = y+50; } g( ) { 1) a = a+x; 2) a = a+y; } Number of possible interleavings of f and g = Number of arrangements of A,B,1,2 such that A$\rightarrow$B and 1$\rightarrow$2 = $\frac{4!}{2!*2!}$ Order a's value A$\rightarrow$B$\rightarrow$1$\rightarrow$2 300 A$\rightarrow$1$\rightarrow$B$\rightarrow$2 300 A$\rightarrow$1$\rightarrow$2$\rightarrow$B 250 1$\rightarrow$2$\rightarrow$A$\rightarrow$B 300 1$\rightarrow$A$\rightarrow$2$\rightarrow$B 300 1$\rightarrow$A$\rightarrow$B$\rightarrow$2 350 1 1 replyShare Please log in or register to add a comment.
0 0 votes as we are adding y to a's value and minimum value of 'a' at point a=a+x; can be 50....so the final value of 'a' (at a=a+y;) has to be greater than 200 (max. value of 'a' can be 350) Punit Sharma answered Nov 10, 2018 Punit Sharma comment Share Follow 0 reply Please log in or register to add a comment.