4 4 votes Consider the following atomic operation:$\texttt{test_and_set(x)}$ sets $x$ to $1$ and returns its previous value.Initially,$x=0$Process $P_1$ executes $\texttt{test_and_set(x)}$, followed by process $P_2$ executing $\texttt{test_and_set(x)}$.Which of the following is correct?$P_1$ returns $0$, $P_2$ returns $1$, and the final value of $x$ is $1$ $P_1$ returns $1$, $P_2$ returns $0$, and the final value of $x$ is $0$ Both processes return $0$, and the final value of $x$ is $1$ Both processes return $1$, and the final value of $x$ is $0$ Operating System goclasses goclasses-cs-dpp operating-system goclasses-cs-dpp-day-334 goclasses-os-practice-questions + – GO Classes 134 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
0 0 votes Giventest_and_set(x): old = x; x = 1; return old; Iska matlab:Pehle purani value return karega.Fir x = 1 kar dega.Ye sab atomically hota hai.Initially: x = 0Pehle P1 execute karega, uske baad P2.p1 ke time x = 0 he ;to old=0x=1return old;p1=0 and x=1now;p2 x = 1; it mean lock accure by p1old=1return old;p2=1x=1 sanjay_Malviya answered Aug 3 sanjay_Malviya comment Share Follow 0 reply Please log in or register to add a comment.