Process X
/* other code for process x*/
while (true) {
1) varP = true;
2) while (varQ == true)
{
/* Critical Section */
3) varP = false;
}
}
/* other code for process X */
Process Y
/* other code for process Y */
while (true)
{
1) varQ = true;
2) while (varP == true)
{
/* Critical Section */
3) varQ = false;
}
}
/* other code for process Y */
For the above piece of code, it can be easily observed that Mutual exclusion isn't ensured i.e. both X and Y can access critical section at the same time. My doubt is regarding whether there exists a deadlock.
Consider the sequence of execution $X_1 Y_1 X_2 X_3 Y_2 Y_1 Y_2\cdots$ where X and Y represent the processes and the subscripts denote the numbered statements. Once the above sequence happens during the concurrent execution of $X$ and $Y$, $X$ stays stuck in its critical section and $Y$ never enters its critical section. Can this be viewed as a deadlock where the access to rest of the code of $X$ is denied by $Y$ and $Y$ is denied access to its CS by $X$?