My task from the teacher is to create a program that solves the three problems using threads in Python: 2 files: reader.py and writer.py In the readers-writers problem there is a common resource where a group of actors called readers want to read from the resource and another group of actors called writers want to write to the resource. The basic synchronization problem that needs to be solved is: 1. Mutual exclusion of the resource, where: • only one writer may print at a time, and • no writer may write while a reader is reading. An ordinary mutex lock that is applied equally to all actors can solve this but will lead to only one actor being able to enter its critical section at a time. This is a problem as we normally want several readers to be able to read at the same time.
My task from the teacher is to create a
2 files: reader.py and writer.py
In the readers-writers problem there is a common resource where a group of actors called readers want to read from the resource and another group of actors called writers want to write to the resource.
The basic synchronization problem that needs to be solved is:
1. Mutual exclusion of the resource, where:
• only one writer may print at a time, and
• no writer may write while a reader is reading.
An ordinary mutex lock that is applied equally to all actors can solve this but will lead to only one actor being able to enter its critical section at a time. This is a problem as we normally want several readers to be able to read at the same time.
The next problem that needs to be solved is therefore the following:
2. Several readers should be able to read the resource at the same time.
In a solution where several readers can read simultaneously and lock out the writers, there is always a risk of starvation in the writers. The more readers and the more time they spend in their critical section, the more unlikely it is that writers will find an opening where all readers are outside their critical section.
The last problem that needs to be solved is therefore the following:
3. As soon as a writer wants to write, new readers must not enter their critical section.1
In other words, writers have priority over readers. As a rule, this is preferable to the opposite as a resource, such as the value of a variable, is out of date for a reader until the writer has updated it. Readers thus read an outdated value while the writer waits.
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)