Look at the third readers-writers problem in the link. By using this definition of semaphores the readers and writers problem can be solved in the following way: Copy Code. ![]() ![]() Consequently, execution of a P operation potentially delays until an adequate number of V operations have been executed. It said in Wikipedia that the code below "adds the constraint that no thread shall be allowed to starve" and I can't understand it why there is no starvation.įor example : what if there are many writers arrive before any readers and the first writer took a very long time to finish his writing then r maybe reach some big minus number lets say -12345 and after it readers begin to arrive along with writers, and somehow the operating system always choose writer to take the semaphore and not reader, in that case the readers would be starve, is that right or am I wrong ? If init is the initial value of s, then in all visible program states, nP < nV + init.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
June 2023
Categories |