Stage 15

61 views
Skip to first unread message

uma damodaran

unread,
Oct 19, 2020, 10:29:06 AM10/19/20
to xos-...@googlegroups.com
Sir,
While waiting for resource like terminal in stage 15, we have been asked to enter into a while loop that invokes the scheduler. But on entering that loop the scheduler schedules another process and the return is to the while loop itself where the terminal status has still not changed. So how does one get out of that while loop , won't this become an infinite loop sir? 
Instead shouldn't the return to be that of another process so that it can free the resource?

Thanking you in advance,
Yours sincerely, 
Uma Damodaran 

Karunakaran Murali Krishnan

unread,
Oct 19, 2020, 1:15:53 PM10/19/20
to xos-...@googlegroups.com
In the loop, if the resource (terminal) is not free, one continues in the while loop.  Otherwise, the loop exits and goes to the next step of locking the resource.
The loop is necessary for the following reason:
Suppose several processes are trying to lock the resource;  one of them will lock the resource and others will wait.  When the resource is released by the process that locked it, all processes waiting for the resource wake up and there is a "race condition".  Here, only one process (the one that gets out of the loop and locks the resource first) must proceed.  Other processes must continue in the loop for the resource to become free again till such time when they eventually acquire the resource.
Did I answer the question?
Murali

--
You received this message because you are subscribed to the Google Groups "XOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xos-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/xos-users/CANjgaua6uJG6TtN45qtgJkxCVmdJvL6vE1kBeCf7Be%2BxEM6WiA%40mail.gmail.com.

uma damodaran

unread,
Oct 19, 2020, 1:21:55 PM10/19/20
to xos-...@googlegroups.com
Sir, 
But in the code given we are calling the scheduler continuously from the while loop. But after the scheduler selects a new process the return statement takes the control back to the while loop itself no sir? So the terminal status remains unchanged because after every call to scheduler the return instruction comes back to the while loop itself. So won't that become an infinite loop?

Yours sincerely, 
Uma Damodaran 

ishan ghosh

unread,
Oct 19, 2020, 1:30:39 PM10/19/20
to XOS Users
The return statement from the scheduler should pass the control to the scheduled process and not the while loop.

Ishan

uma damodaran

unread,
Oct 19, 2020, 1:32:37 PM10/19/20
to xos-...@googlegroups.com
Oh okay. Thank you.

Karunakaran Murali Krishnan

unread,
Oct 19, 2020, 1:42:32 PM10/19/20
to xos-...@googlegroups.com
the return statement takes the control back to the while loop itself no sir?
true.
So the terminal status remains unchanged.
Not true.  Only when the terminal status changes, the process (or any process waiting for terminal) is scheduled again (by the scheduler).

However, the "race condition" is that only the first process that is scheduled after the terminal status becomes "free" is able to acquire the terminal.
This process will lock the terminal again.  Hence when other processes are scheduled, the will find the terminali is locked again and will go to wait state again.
(This keeps happening for a process till eventually it is the "first process" to be scheduled after waking up from wait state.   

uma damodaran

unread,
Oct 19, 2020, 1:49:42 PM10/19/20
to xos-...@googlegroups.com
Okay sir, understood. Thank you for clearing that up.

Yours sincerely, 
Uma Damodaran 

Murali Krishnan

unread,
Oct 19, 2020, 2:21:12 PM10/19/20
to xos-...@googlegroups.com
Please have a careful look at the scheduler code.
If process 1 calls the scheduler, then the return may (and most likely) happen to another process - say process 2. 
Process 2 can - for instance - change the terminal status before the scheduler returns to process 1. 
The scheduler returns to process 1 after several -call scheduler and return to process steps between the scheduler other processes. 

uma damodaran

unread,
Oct 19, 2020, 10:24:46 PM10/19/20
to xos-...@googlegroups.com
Yes sir, I'll check the scheduler code again. 

Yours sincerely, 
Uma Damodaran 

Reply all
Reply to author
Forward
0 new messages