179 views

Consider  the two processes need to access $P_{i}$ and $P_{j}$ need to access the C.S. The following synchronization construct used by both the processes.

Process Pi

While(true){
j=false;
i=true;
while(j==true);
CRITICAL SECTION
i=false;
}

Process Pj

While(true){
i=false;
j=true;
while(i==true);
CRITICAL SECTION
j=false;
}


I got it is not satisfying M.E., but will it satisfying deadlock too??

Plz explain-

| 179 views
+1

Yes, but that should be spinlock actually.

say after execution of Pi 's

While(true)

{

j=false;

the process Pi is preempted, and Pj gets the turn.
Now say Pj after executing -->

While(true){

i=false;

j=true;

gets preempted and the control goes back to Pi, now Pi executes --> i=true;

Now see that both the while conditions of both the processes are satisfied. So they will be in a spinlock.

+2
 j=false; // in Pi then Context switch to Pj
 i=false; // in Pj then Context switch to Pi
 i=true; // in Pi then Context switch to Pj
 j=true; //in Pj then Context switch to Pi
while(j==true); // in Pi then Context switch to Pj (stuck in loop)
while(i==true); //since i is true it also gets stuck in loop

+1
I think spinlock actually..becuase deadlock means everything should Halt, but in spinlock we are continuously checking whether our required condition is satisfied or not. And here also we are running continously in a while loop. So spin lock must be the appropriate answer.
0
not livelock

right??
0
Got no idea what a Livelock is..
+2

why r u telling spinlock??

Spinlock means one process already in C.S. and other pricess spins before lock. But deadlock means no work can process there. Right??

Chk  livelock here https://gateoverflow.in/156236/livelock-and-spinlock ?

+2

In concurrent computing, a deadlock is a state in which each member of a group of actions, is waiting for some other member to release a lock.

A livelock is similar to a deadlock, except that the states of the processes involved in the livelock constantly change with regard to one another, none progressing.

here the states of the process are not changing so it is not livelock.

If you notice that in this question there are 2 spinlocks and

Attempting to acquire a second spin lock while holding another spin lock also can cause deadlocks.

so here it is deadlock not spinlock.

0

yes, it should be Deadlock. Turns out my concept was not clear on spinlock. Thanks @srestha    and @Satbir

0

@srestha

@Satbir

Mutual Exclusion should be a necessary condition for deadlock, right? So how can this code be in deadlock? I think we went wrong somewhere..

+2
both the inner while loops becomes true and deadlock occurs. $\implies$  here deadlock is coming because there is mutual exclusion between while loops and not because of mutual exclusion between processes.
+1

@Hirak

Now u get the point. right??

+1

@Satbir. You are right.

go through this comment--   https://gateoverflow.in/8405/gate2015-3-10?show=93533#c93533

0
Okay, i got it, thanks all for your guidance.. :)

+1 vote

by Boss (34.6k points)
selected by
+1 vote

Solution:-

by (143 points)