- The mutex semaphore is used to ensure mutual exclusion when the variable read count is updated. - The read count(rc) variable keeps track of how many processes are currently reading the object. - The semaphore rw_mutex(db) functions as a mutual exclusion semaphore for the writers. It is also used by the first or last reader that enters or exits the critical section. - It(db) is not used by readers who enter or exit while other readers are in their critical sections. ** Note that, if a writer is in the critical section and n readers are waiting, then one reader is queued on rw_mutex(db), and n − 1 reader are queued on the mutex. Also observe that, when a writer executes signal(rw_mutex), we may resume the execution of either the waiting readers or a single waiting writer. The selection is made by the scheduler. -> From Galvin
The way u explained sir it's impeccable n ur content is lucid ..really v helpful for everyone of computer science students irrespective of whether preparing for gate or not... Really a nice initiative..it's a kind of home tuition for free Thnx a lot sir
Also mutex is used while running reader exit section code if it gets preempted and another reader tries to run , it wont work . It can mess up rc value. so rc value is also protected by mutex
@@shinobiwolf8133 What Vignesh trying to say is, "whenever we are going to update the rc value, we must down the mutex otherwise 2 or more readers can update the same rc value at same time which can result in locking the db permanently because rc value will never become zero. e.g. if rc =5 at some point, and 3 readers at the same time decrease it by 1, then all 3 of them will be decreasing it from 5 to 4. However, if you down the mutex before updating the rc value, then other readers will have to wait for the rc value to decrease by previous reader.
Hello sir, I'm studying Integrated MCA and I was worried about my OS subject but after watching your videos I'm very much thankful to you. I appreciate your hardwork. May God bless you. I have an request sir Please make a video on concept of Monitor in OS. Waiting in hope for your response.
In my Engineering I didn't took this seriously, Now when preparing for product based company I am preparing and thanks a wonderful explanation. I understood everything. Hope to crack a good company.
Hi sir, I genuinely love your teaching! Your lectures have made me fall in love with this subject! I have a doubt though. Why is mutex being used again and again, I can't understand the application of it Hope to hear from you soon! Thank You
I think that's because the statements rc=rc+1 and rc=rc-1 are sensitive to pre-emptiveness, recall to the most basic problem of process synchronization that was explained in one of his previous videos.
wah sir kya bt he kitna acha ap hr chez explain krte hu kya concept clear krwae ap ne bs ase hi acha acha smjate rhe ap ne tu sari problem hi solve kr di hmari thnkiooooooooooooooooooooooooooo
Vry useful video sir.. No any doubt to say sir you are magician of knowledge.. N teach all topics with pateince.. Concept is properly cleared.. Thanxu sir
Thank you so much for making this playlist, its really a godsend. All the videos are to the point and yet contain enough examples and explanations. I only had one small doubt, what is the use of the mutex semaphore in this question? Wouldn't the code run exactly the same for all cases even without the mutex semaphore?
Sir I think you should recheck your W-R case again... After the write is implemented, you didnt up the value of db. That is why in the read function, after passing the rc==1 case, when the value of db goes down again, it should be zero and not negative. Kindly see that part though. I too may be mistaken but just got that observation.
one of the best teaching😍😍😍thank you so much sir.....in class os is so boaring and difficult,but after watching your videos feels like os is so intresting and easy 🤩🤩😛
Sir, Can you discuss the cases in Producer-Consumer Problem like i) If down(empty) interchange with down(mutex) likewise there are four cases if you can discuss it will be very useful.
Thank you so much sir. Your videos have taught me a lot. I just don't understand why you have used the while(true) loop in reader() and writer() functions. Can you please explain?
Sir you have explained everything so nicely.Great Job! I just wanted to ask whether this problem is important for interview preparation? And if so , do we have to learn the code as well?
thank you @gatesmaashers for being help us in all the topics of different subjects. your are such an amazing person and you your teaching method means no word i have to explain means amazing fabu . thanks alot again sir great work!
if there is no mutex semaphore in the above solution we might go into deadlock situation.....here is the case: 1st reader enters critical section ...so rc=1 db=0 ...after sometime he comes out of critical section and executes exit code rc=rc-1 so rc=0 ..now before it executes if statement lets say another reader preempted and executes entry code rc=rc+1 so rc=1 and it tries to execute if statement but db=0 so reader 2 gets blocked here......now lets say reader 1 continues to execute....now when he tries to execute if statement at exit code....he can't go inside if, cause rc=1. so deadlock situation.
Role of mutex is to maintain the presence/absence of readers in the db, and if R-R can occur(this is managed due to up(mutex) only) but R-W or W-R can't occur is managed by the db Semaphore
For those who are thinking about why mutex is used? => The mutex semaphore is used to ensure mutual exclusion when the variable read count is updated. Thank u!
I think condition in reader should be (rc>=1), not (rc==1), if(rc==1) then any no. of reader except 1st reader can enter into critical section after 1st writer, so RAW problem is still holding.
Sir with utmost sincerity and respect i would like to tell you that i have a doubt in the 4th case of R-R. You said *_"if the 2nd reader comes in then rc increases to value 2 and then execute down(db) which it cannot change back to 1 and therefore this line gets blocked."_* If this line is not executed and blocked then how is it possible to execute the next line? It should remain blocked forever. The next line should not be executed until the down(db) value is modified.
Hi harsh Pandey if(condition) statement; if there is no braces with the if statement then by default we consider only one statement under the if condition to be executed if the condition is true.. so the statement down(db) is the part of if condition not up(mutex). therefore next line continue to its execution ...
Okay !! That is why u wrote that statement in 1 line. I caught my mistake. Thank you Sir, I have almost seen all your videos and some are yet to be seen. I have recommended your videos to most of friends who have not touched these topics since 3 years after graduation. These videos are very much knowledgeable and i wish to see more videos of yours regarding programming language Python.