ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > ZSTU-(2020-2021)-1 > student homework > 2018529627022_FESHETE CHARLES DE-GAULLE >
Homework-7_2018529627022_FESHETE CHARLES DE-GAULLE Version 0
👤 Author: by cfeshete97gmailcom 2020-11-13 07:27:35
Read writer’s Problem

Readers writer problem is an example of a classic synchronization problem.

 

The Problem Statement

There is a shared resource which should be accessed by multiple processes. There are two types of processes in this context. They are reader and writer. Any number of readers can read from the shared resource simultaneously, but only one writer can write to the shared resource. When a writer is writing data to the resource, no other process can access the resource. A writer cannot write to the resource if there are non zero number of readers accessing the resource at that time.

a)

  1. Mutual Exclusion: When a Writer is writing data no Reader or other Writer can access the data to prevent more than one thread modifying the data.

  2. Hold and Wait: A shared file for a Writer is locked and only released when modifying is done. Writers are allowed if there are no readers requesting it.

  3. No Preemption: Readers cannot request data that is currently being modified by a Writer likewise if data has Readers Writers cannot request to write into the file.

  4. Circular Wait: if many Writers want to modify the data they have to wait one after another in a circular manner until they all get a chance since this can’t be done simultaneously.


 

b.)   Readers Preference Solution

In this solution, preference is given to the writers. This is accomplished by forcing every reader to lock and release the readtry semaphore individually. The writers on the other hand don't need to lock it individually. Only the first writer will lock the readtry and then all subsequent writers can simply use the resource as it gets freed by the previous writer. The very last writer must release the readtry semaphore, thus opening the gate for readers to try reading.

No reader can engage in the entry section if the readtry semaphore has been set by a writer previously. The reader must wait for the last writer to unlock the resource and readtry semaphores.





 

 

 

 

 

 

Please login to reply. Login

Reversion History

Loading...
No reversions found.