OPERATING SYSTEM - PROCESS SYNCHRONIZATION PART 3-HARDWARE SYNCHRONIZATION USING TEST AND SET

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this session is focused on hardware synchronization to solve the critical session problem so let's have a base on what we have studied in the last session video now solution to critical session problem can be ranging from software to hardware application for program interface the software solution would be Sawyer's Peterson solution in the previous video you can refer the previous video to understand Peterson solutions in a better way and the limitation to critters in solution was it is applicable only to maximum to process that was the first drawback and it is not adaptable to the modern computer architecture so we don't know whether it will work in the modern computer architecture that was a restriction to the Peterson solution so if you think about the hardware solution one of the solution is disable entrance if you think about a uniprocessor system wait if I think about one processor who is trying to access the critical session then I know that the other process will access the critical session only if process P even completes its entire execution that is what uniprocessor one process is executed then only the next process executes in so there is no chance of a race condition existing in a uniprocessor system but in a multiprocessor system so what we do in a uniprocessor system as we disable the interrupts when our particular processes executing its critical session part or shared variable part but in a multiprocessor system if a particular process is accessing the critical session other processes who are trying to run parallel you have to send a message to all other process saying that I am performing the critical session you all disable the interrupt so this message passing takes a lot of time so message has to be reached to the other process to disable its interrupt they are not raising any interrupts so that P one is not getting preempted and the entry to critical session Thursday lace because message has to be reached the acknowledgement has to come and then anyone can enter into the critical session as well as when a p1 is executing the critical session I am deceiving all the interrupts including the system interrupts the updation of time etc will be affected so I cannot go for a solution where I am going to disable interrupts in a multiprocessor system that is not at all a feasible solution so we will go for hardware synchronization method where we use a special hardware instruction there are two special hardware instruction what we use the first one is test and set that means a test and then modify a content of a word and another particular hardware instruction is swap that is swab the contents of two words and the feature of this particular instruction is it performs atomically it acts as a or it is executed as a one uninterruptible unit at us and it performs as one uninterruptible unit this is a main feature of this particular hardware instruction so let's see how the test and set has been executed in test and set we have the definition of test and set function as boolean test and set - it so we initialize target which is pointer to a memory address so let it be our target over here and it is a boolean function so target can have only two values either true or false one of the value and I initialize a return value register so our V which is also boolean function and it also can be either true or false now this is the definition of boolean function I have just numbered over here I will come to it later now boolean are V is equal to pointer target so let's start from over here by initializing my target is equal to false so here it is false and here I will just assume our V is equal to 2 and condition can be taken or let me assume both are false as a first case which I have taken over here boolean are V is equal to pointer target whatever the values in the target it is transferred to our V so are we now will be having false that means this will be transferred over here and the second line that is the first line the second value is second line says that pointer target is set to true so this will be set to two so what happens initially both way Falls after the execution of line number one RV is set to false and target will be set to true and third line say will return the value of our V what is the value of our V after the target value has been pushed into our way it responds so the outcome is false the second condition is this is true and our V is true and target is false so here this is false and this is true after the line number one avi has the value of target so target is false so our V becomes false and target is set to true the second line is target is always set to 2 so this becomes true and return the value of avi avi is false so this becomes false the third case is our V is false and target is true the first line says that boolean our V is equal to target so our V is getting the value of target so it is true and target a sector true in the second line over here so this becomes here true and false to and true and the return value is true so it is true that line number three ends up with the true value and the fourth is true and true so here both are true so our we will get the value true after the first line and second line sets the target and the return value of our V is true so the outcome is true so this is what we have the four cases what I have taken over here anyhow after the line number two you can see that always the target are set to true so according to definition the return value of RV is not used to test and set condition so I have written over here if the initial value of target is false a return value and so will be false if the target initially is true this is going to be true so from here you can see that initial value of target if it's false outcome is false here also false here also false when it's true it's true here are true here true so this is a base concept what we are going to use in the implementation part in the implementation part a process has to execute the following code any process who want to go for the accessing the critical session has to access this particular core first it is - it runs a code that is I can use your line number one saying that why test and set and lacA so however I call our test and set unlock it will call this particular function bool in distance it and point at our thickness the lock is nothing but the target value so I will replace the target with the lock okay and boolean avi is a pointer target so whatever changes we have in the target value it will be reflected on the lock it is passing by reference function so whenever I'm calling and lock it will call this particular function and the modification made in the target will be reflected onto the lock so if you remember in the previous session whenever a particular process want to enter into the critical section it has to have run an entry section code entry section code to acquire lock to acquire lock and once it gets the lock it enter into the critical session and once I finish it has to run the exit session code to release the lock so this was a basic concept what we have seen from the beginning of processing canalization so it is a release lock so in this particular code whenever a process want to enter into the critical session this becomes the entry section code this part and this becomes the exit section code so let us say the increment so as I said and Locke is here over the target values in critical section problem we are going to check three condition the first conditional first requirement is mutual exclusion the second is progress and third is waiting bounded wait you can refer the previous videos for the basics of critical section problem and processing realization so let me assume there are two process p1 and p2 who are competing for critical session and first P even try to enter into the critical session so I will just to make our table column with updation of lock value so lock as a global variable so I will show you know lock is a global variable so whatever the value of Locker p1 and p2 can see those value let me initially is the lock value as false so in the first condition lock a set to false we won't try to enter into the critical session so while test Ansett and lock so lock is initialized to false so when this is run the code while test and set an target we see that the return value is going to be false so the while condition is false over here and p1 enter into the critical session I'll repeat whenever a particular process try to enter into the critical section suppose V 1 is trying to enter it run this particular code while test unsaid and law lock values false if lock value is false return value will be false so after ending the while test and I said the return value will be false thus if enter into the critical session if it was true it would be looping over here itself now the condition is false so it enters into the critical session so p1 after let me name this as line number 1 critical section is a big code but I'll say it as step number 2 this is step number 300 it'd be step number 4 so P even ran the says line number 1 or step number 1 the condition becomes false and it entered into the critical session now according to the requirement mutual exclusion should be maintained that means when p1 has entered into the critical session p2 should not be allowed to enter into the critical session now after entering the critical session I have one more condition that is in our violent I started after entering the return value will be false but the lock value will be set to true but after doing it lock will be sector true so here the lock will be set to true if you see the definition of critical session using test and set I said the target will be set to true in the line number 2 so here second over here this becomes true and now p2 is trying to enter into the critical session as a definition or as a requirement p2 should not be allowed to enter into the critical session because P 1 is executing the critical session let's see if p1 p2 tries it has to run this while test and set lock what is a lock value right now true so it will return the value true so this condition becomes true and p2 will be blocked here itself without allowing to enter into the critical session so p2 it runs the first step that is while condition and return value will be equal to true hence it will be blocked from entering into the critical session so what we have seen in here when p1 is accessing the critical session p2 is blocked from the entry of critical section so its first mutual exclusion has maintained now when can it enter when P even finishes the critical section when P even finishes the critical session the lock is set to false so here and third when P even finishes critical session so let me say it finishes critical session lock is set to false when locked a set of false what happens now your p2 is going on drying so here also p2 will be checking in the while condition test and sit no lock is false then my return value will be false then it enter into the critical session and they're entering into the critical session what is before entering into the critical session it will obviously set the lock to true so lock is equal to true this would have entered its remainder section when this finishes the critical session this would have entered into the remainder section so we can see here when p1 finishes a critical session it is not blocking p2 to enter into the critical section and the maintenance of mutual exclusion as they and now let me say when this entered into the critical session you can try yourself pthey is trying to enter into the critical session now what is the current value of a lock the current value of the lock is true when P 3 tries it sees this while condition becomes true and the return value is true and P 3 will be looping here itself without having the access to critical session so again P 3 cannot enter when P 2 is accessing the critical session so again the mutual exclusion is maintained so the first condition or the first requirement using the test and lock is satisfied the second condition is our second requirement is progress we will check whether the second requirement through CRA's is been satisfied so you know critical session problem solution using test and set it does two things that is whenever it performs test and set we have the initial value of LOC is equal to false so when it performed test and set so initial value of lock it will be testing what is the initial value of LOC this value will be returned so returned variable will give me the value false and the lock will be set to 2 lock will be set to true remember whenever we function with the distance it it does two things first it checks the in value of the lock which is returned for the while condition and if the while condition is false then it enter into the critical session and the lock will be set to true at the same time so let's check for the progress now process p1 enters into the critical session by checking the condition while distance set since the lock is false it sets first it checks value of log which is false then it said lock is equal to true so here it is set to true and then it enter into the critical session now after performing the critical session it for phone lock is equal to false so again lock is set to false so this becomes false and then it goes to the remainder section now when it is performing remainder session or I can say it is just going to the sleep later that means it doesn't further want to participate in the critical session at the same time p2 was waiting to enter into the critical session when p1 was performed performing the critical session where it was blocked to enter into the critical session because of the mutual exclusion property so when p1 comes to the remainder section on sleep the lock is set to false P to go with the wild piston set lock lock is false and it said the lock is equal to true and then it enter into the critical session after coming from a critical session lock is again set to false then it goes to the remainder session but when it reaches a remainder session it says that I want to enter once more into the critical session it whether it can do so it can do so because lock is already set to false and it can come back again it is the same procedure setting the lock is equal to true testing the value of law the condition becomes was it again entering to the critical session again it does the same thing again it come to the remainder session again it want to participate where p1 is not blocking PT to enter into the critical section multiple times all let me say when P 2 finishes p3 is trying to enter into the critical session that also can happen because when p1 accept me to exit from the critical session it said the lock is equal to false so when a p3 tries for the while condition it test the lock is equal to vote said the lock is equal to 2 as the same over here enter the critical session and continues with the same procedure where p1 was not blocking other process to enter into the critical session it does mean that if any particular process to compete for the critical session only we'll be participating to enter into the critical session p1 was sleeping it was not although it had a critical session it was not participating in the competition of critical session that doesn't mean the progressed so the second condition is also satisfied and the last requirement is bounded waiting let us check whether the bounded waiting condition is met in bounded waiting condition p1 it checks the lock is equal to false said the lock is equal to true so it becomes true over here enter into the critical session then lock is equal to false as over here that is falls over here come to the remainder session and then try to exit so when this is performing the critical session let me say p2 wanted to enter into the critical session but when our p1 reaches the regular session it says that it want to again participate into the critical session can it do so yes because here whenever it is checking for the second time this was the first and second time when it is checking its checks whether the lock has faults ears lock this one's set it to true go for the critical session p1 will be waiting for the first time now third time also p1 p1 tries and let me assume p1 is having a priority than p2 so P p1 enters again so this is waiting for the second time also now again for the time this enters this is waiting for the third time so this is entering for the fifth time this is waiting for the fourth time there is no bound at time limit of apts p2 is waiting to enter into the critical system so as many times p1 want to enter it can enter and do so because lock is set false by p1 itself and p1 is repeatedly participating and entering into the critical session and p2 is without a bound limit of waiting it is going on waiting which is nothing but a starvation the starvation problem so the bounded condition over here is not met or it is not able to satisfy the boundary waiting but it can be a good solution for the critical session problem still it has some drawbacks like application programmer doesn't find it easy to apply this hard way synchronization tool for critical session problem in the upcoming videos we are going to see hardware based synchronization using the swap function using this app function and later we will see the classic synchronization problem and how we are going to solve those problem using semaphore
Info
Channel: Tutorsgate
Views: 3,157
Rating: 4.9259257 out of 5
Keywords: process synchronization, hardware synchronization, test and set(), testandset, tutorsgate, Tutors gate, shamna, shamnanv, operating system
Id: vl86XyHBGCc
Channel Id: undefined
Length: 20min 27sec (1227 seconds)
Published: Wed Jun 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.