If there's 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 :)
sir initially its written that multiple readers can access the file, but in code only one reader is allowed at a time and other reader wait at mutex. why?
we can't let mulitple readers access the readcount variable at the same time..thats why we gotta use wait(mutex)..however once the readcount++ is done and signal(mutex) too...other reader can now access the file..so we gotta use preemption at the end of 1st signal(mutex) for multiple readers to be able to read