P(s1);
a++;
P(s2);
v++;
V(s2);
V(s1);
(s1, s2 are semaphores). All variables are automatic. Now, consider two threads running this fragment of code simultaneously, can there be a deadlock? Why, or why not?
if(a > 0)
P(s1);
else
P(s2);
b++;
P(s3);
if(b < 0 && a <= 0)
P(s1);
else if(b >= 0 && a > 0)
P(s2);
else
P(s4);
a++;
V(s4);
V(s3);
V(s2);
V(s1);
s1, s2, s3 and s4 are semaphores. All variables are automatic. Now, consider two threads running this fragment of code simultaneously, can there be a deadlock? Why, or why not?