The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
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-

in Operating System by Veteran (115k points) | 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

hence there is deadlock.

+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

@Hirak @Satbir

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.

so its deadlock.


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.

https://en.wikipedia.org/wiki/Deadlock


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.

read the last paragraph.

https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/preventing-errors-and-deadlocks-while-using-spin-locks#nested-spin-lock-acquisitions

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
+1

@Satbir. You are right.

@Hirak 

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

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

2 Answers

+1 vote
Best answer

Dead lock is present

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

Solution:-

by (143 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,092 questions
55,322 answers
190,847 comments
86,228 users