I think the if (readcount == 1) wait(wrt); part would be best explained like this: when we are reading, no one should be allowed to write, thus the wrt semaphore should be acquired; so if we are the _first_ reader, we acquire it (and wait till it's released if someone's still writing); but if someone's already reading, it means they have already acquired wrt, so we just skip this part. Similarly, in the if (readcount == 0) signal(wrt); line, we check if we are the last reader, and if we are, it's our responsibility to release wrt, thus allowing others to write.
If someone like me who's struggling to understand how multiple processes can read without allowing any other process to write, it can be explained in this way: When the first reader process enters it decrements the wrt and makes it 0 so that no writer process can execute untill the last reader has done its job and signals wrt. Therefore, after the first reader process, other readers which will try to read concurrently will skip the if(readcount ==1) part since wrt is already decremented by the first read process and write() operations are halted. I hope it helped you :)
I am studying in the morning and today is my exam belive me i wasnt able to understand and was very tensed and frustrated bcoz of this topic but when i visited this channel i felt its soo easy.. thanku so much ❤️
i have one doubt imagine 2 reader and default mutex is 1 . if 1st reader comes in wait he makes mutex to 0 .Inside if condition reader1 will restrict writer .After restricting writer he is allowing one more reader by signal(mutex) so mutex is 1 .reader 2 uses this and now mutex is 0 and reader 2 again increases to 1 . if user 1 has to level. before leaving wait(mutex) he will perform so it will 0 now if reader 2 has to leave he has to perform wait(mutex) now its a dead lock for reader2 any body can explain
Reader 1 ensures to signal (mutex) before exiting, making it available for Reader 2 to use wait (mutex), thus eliminating the possibility of a deadlock.
I think the signal(mutex) should come before : if(readcnt==0) so that after decrementing the readcnt the other readers can enter before releasing the wrt
I think you have missed something the control goes to readcnt==0 if there are no readers left so in such a case the wrt lock must be released and mutex must also be released, The mutex lock held by a reader is released after it enters the critical section (given as signal mutex), so this ensures other readers can enter the critical section. here indentations are used to separate the code you may have missed it.
this program seems to give more priority to the read operations. So going by the code, once a read operation acquires the wrt semaphore, it will only release it if readcount is 0 - thus if read processes keep coming in, I believe it will cause starvation for the write process, isn't it? So bounded waiting for effective process synchronization is not satisfied. How to improve this to implement bounded waiting?
In readers writers problem we are used bounded buffer with fixed size and at there our main goal is to prevent overflow and underflow. But at readers writers problem the process is accessing shared resources like database or files. Here our goal is to allow concurrent reads and exclusive writes. Like this there are various key differences between those two problems bro
signal(wrt)allows a writer waiting to write. If a process wants to read it can. wrt is only to prevent writer from writing. wrt is the mutual exclusion semaphore to prevent from writing. mutex here is to lock readcount variable.
if readcoun==0 signal wrt / why should we wait all the readers to execute so we allow the writer to enter , perhaps the writer was there before some numbers of writers came , isnt this a sort of privilege that shouldn't happen in mutual exclusion ? (sorry for this broken English lol)
They're following c style syntax for writing their pseudocode, in C if (...) statement1; is same as doing if (...) {statement1; statement 2; ....} Which is to say, immediately execute whatever that comes after "if", if "if's" condition is true, that "whatever" can be a block of statements or a single statement. Edit: Indentation does not matter in C, all that matters is, semicolon and curly braces. Edit2: int main() needs a curly-brace because int main is a function definition. Function definition needs curly braces. (Why? I do not know)
I see a problem with this solution : while reader 1 is currently reading, reader 2 can enter, readcnt is now =2, reader 1 finishes reading, he can’t continue to next line because the condition of readcnt ==0 isnt met. Now that readcnt is ==1 again, reader 2 continues. Now At this same time reader 2 can’t continue either because she cant get past the wait(wrt) condition since the lock is still held by reader 1. Reader 1 is waiting for reader 2 and vice versa. A traffic jam indeed!
last line signal(mutex) shouldn't be in the indentation (if statement), should be outside of the if statement, so that it won't have this problem I guess
I think the
if (readcount == 1) wait(wrt);
part would be best explained like this: when we are reading, no one should be allowed to write, thus the wrt semaphore should be acquired; so if we are the _first_ reader, we acquire it (and wait till it's released if someone's still writing); but if someone's already reading, it means they have already acquired wrt, so we just skip this part.
Similarly, in the
if (readcount == 0) signal(wrt);
line, we check if we are the last reader, and if we are, it's our responsibility to release wrt, thus allowing others to write.
Yep, this works too!
@@chadj1797 it's not "this works too!", it's how it's supposed to work
you're absolutly right
You are the GOAT
Thank you so much, my doubt cleared from your comment, are you from Russia?
This was a good explanation of something that is not explained well in the textbooks. Good job.
If someone like me who's struggling to understand how multiple processes can read without allowing any other process to write, it can be explained in this way:
When the first reader process enters it decrements the wrt and makes it 0 so that no writer process can execute untill the last reader has done its job and signals wrt.
Therefore, after the first reader process, other readers which will try to read concurrently will skip the if(readcount ==1) part since wrt is already decremented by the first read process and write() operations are halted.
I hope it helped you :)
Dude you are amazing, I am learning more in one video than a full lecture my professor gives.
12:18 readcnt >= 1 cuz if it is updated to more than 1 writer process can start updating .
I am studying in the morning and today is my exam belive me i wasnt able to understand and was very tensed and frustrated bcoz of this topic but when i visited this channel i felt its soo easy.. thanku so much ❤️
Good Explanation , but how wrt decide that whether the requested process is for reading or writing
Well explained,... Got every bit of this problem
i have one doubt imagine 2 reader and default mutex is 1 . if 1st reader comes in wait he makes mutex to 0 .Inside if condition reader1 will restrict writer .After restricting writer he is allowing one more reader by signal(mutex) so mutex is 1 .reader 2 uses this and now mutex is 0 and reader 2 again increases to 1 . if user 1 has to level. before leaving wait(mutex) he will perform so it will 0 now if reader 2 has to leave he has to perform wait(mutex) now its a dead lock for reader2 any body can explain
Reader 1 ensures to signal (mutex) before exiting, making it available for Reader 2 to use wait (mutex), thus eliminating the possibility of a deadlock.
Such a nice explaination , make topic very easy 📌📌
This is one of the Best explanations!!!!!
Thanks a lot... It was soo confusing before and this was soo helpful❤
Nice explanation thanks for supporting us!
May god bless you with the Health ❤❤
thanks, it was very nice explanation, crisp and clear
Best explanation ❤
Our teacher taught this wrong in the class..dumb
I think the signal(mutex) should come before : if(readcnt==0) so that after decrementing the readcnt the other readers can enter before releasing the wrt
I think you have missed something the control goes to readcnt==0 if there are no readers left so in such a case the wrt lock must be released and mutex must also be released,
The mutex lock held by a reader is released after it enters the critical section (given as signal mutex), so this ensures other readers can enter the critical section. here indentations are used to separate the code you may have missed it.
@@30benasabu65
can Signal(mutex) come before the signal(wrt)?
It would be nice if there was an implementation in C.
this program seems to give more priority to the read operations. So going by the code, once a read operation acquires the wrt semaphore, it will only release it if readcount is 0 - thus if read processes keep coming in, I believe it will cause starvation for the write process, isn't it? So bounded waiting for effective process synchronization is not satisfied. How to improve this to implement bounded waiting?
Any suggestions?
Do we have to learn these codes for theory exams or its just to learn the basic theory?
I guess we need to create an other semaphore to maintain a queue that involves both readers as well as writers.
Very nice explanation sir 👍👍
@Neso Academy signal(mutex) is outside the if block or inside the if block ?
outside \
#nesoacademy
Very well explained! Thank you so much!!
i mean if you think about it . a reader is like a consumer and a writer is like a productor . so why not same logic
In readers writers problem we are used bounded buffer with fixed size and at there our main goal is to prevent overflow and underflow.
But at readers writers problem the process is accessing shared resources like database or files. Here our goal is to allow concurrent reads and exclusive writes.
Like this there are various key differences between those two problems bro
Great video!
Why do we need mutex semaphore to ensure the mutual exclusion of readcnt?
well, you may know about the race condition. To avoid it we need a mutex
@@bhaskarmishra8479 can you tell more about it ?
Thank you so much 😊
Thanks
Thnks a lot ❤️
mutex is a binary semaphore , then wrt is counting semaphore?
Well explained
now signal(wrt) means both readers and writers can access it right?
signal(wrt)allows a writer waiting to write. If a process wants to read it can. wrt is only to prevent writer from writing. wrt is the mutual exclusion semaphore to prevent from writing. mutex here is to lock readcount variable.
I think the mutex for read count is no need
Good one
Chota packet bada dhamka😂
Writers process 😊 readers process😮😢
Great video :)
this solution has a starvation problem. am I right?
Very good explanation!
Salute to you
Awesome !!!
if readcoun==0 signal wrt / why should we wait all the readers to execute so we allow the writer to enter , perhaps the writer was there before some numbers of writers came , isnt this a sort of privilege that shouldn't happen in mutual exclusion ? (sorry for this broken English lol)
more readers can be there , but writer can only come when readers become 0 so its signalling
Is the last signal(mutex) inside reader process having a wrong indentation?
They're following c style syntax for writing their pseudocode, in C
if (...) statement1; is same as doing
if (...) {statement1; statement 2; ....}
Which is to say, immediately execute whatever that comes after "if", if "if's" condition is true, that "whatever" can be a block of statements or a single statement.
Edit: Indentation does not matter in C, all that matters is, semicolon and curly braces.
Edit2: int main() needs a curly-brace because int main is a function definition. Function definition needs curly braces. (Why? I do not know)
I think so too. Doesn't make sense to wait till the last reader to release mutex. Correct me if I'm wrong.
that indenting is so confusing in reader process
I believe this is the proper indentation.
do {
wait(mutex);
readcount++;
if(readcount == 1)
wait(wrt);
signal(mutex);
/*current reader performs reading*/
wait(mutex);
readcount--;
if(readcount == 0)
signal(wrt);
signal(mutex);
}while(TRUE);
please correct if I'm wrong.
@@andrewbabilonia77 ya true I checked on Internet loll
I see a problem with this solution : while reader 1 is currently reading, reader 2 can enter, readcnt is now =2, reader 1 finishes reading, he can’t continue to next line because the condition of readcnt ==0 isnt met. Now that readcnt is ==1 again, reader 2 continues. Now At this same time reader 2 can’t continue either because she cant get past the wait(wrt) condition since the lock is still held by reader 1. Reader 1 is waiting for reader 2 and vice versa. A traffic jam indeed!
last line signal(mutex) shouldn't be in the indentation (if statement), should be outside of the if statement, so that it won't have this problem I guess
@@AmpangNation Yes I think you're right
good video
Pls upload in neso website and app also simultaneously
I think it's already there.
@@rajeshprajapati4863 no not all the video available
@@azadr OS Subject is complete on app and website too. Check Again.
@@rajeshprajapati4863not only with respective to os I was talking about all other subjects which were upload in youtube but not on neso
adamsin
🙏🙏🙏❤️❤️❤️❤️
1st comment
👏