My task from the teacher is to create a program that solves the three problems using threads in Python: I start a little bit with it but I don't know how to complete it.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

My task from the teacher is to create a program that solves the three problems using threads in Python:

I start a little bit with it but I don't know how to complete it. 


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.


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.


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



 Use the threading module  for the actors: readers and writers.
The shared resource to be implemented is a text string.

Two different writers are continuously trying to write to the text string.

One writer is writing a date stamp all the way down to seconds.

The other writer writes the same thing, although the string writes backwards.
At least three identical readers simultaneously tries to continuously read the text string and print it to the standard output stream. See also Table for a summary.

Actor Total Task
Reader 3 Reads and prints the text string to the standard stream.
Writer 1 Writes a date stamp, including seconds, to the text string.
Writer 1 Writes a reverse date stamp, including seconds to the text string
C:\Users\Unix\Desktop\reader.py Sublime Text
C\Users\Unix\Desktop\writer.py . - Sublime Text
O X
File Edit Selection Find View Goto Tools Project Preferences Help
File Edit Selection Find View Goto Tools Project Preferences Help
reader.py
writer.py
1 # readers
1
# writers
2
var # global var
4 locktite # ska skydda var
3 var # global var
4 locktite # ska skydda var
5 writerpriolock # ska ge prio till skrivare
5 counter
6 lockcount # ska skydda counter
7 writerpriolock
7 v while (True):
writerpriolock.acquire()
# <---- en skrivare är här
locktite.acquire()
8
9 while (True):
writerpriolock.acquire() # <--- två till läsare
writerpriolock.release()
lockcount.acquire()
counter++
if (counter
locktite.acquire()
lockcount.release()
10
10
11
11
I
12
12
var =
something
13
13
14
== 1):
locktite.release()
writerpriolock.release()
14
15
15
16
17
18
print(var)
19
lockcount.acquire()
counter-
if (counter
locktite.release()
lockcount.release()
20
21
22
0):
33=
23
24
25
# <--- en läsare här
14 characters selected
UTF-8
Tab Size: 4
Python
O Line 14, Column 18
UTF-8
Tab Size: 4
Python
11:59
2021-03-09
Transcribed Image Text:C:\Users\Unix\Desktop\reader.py Sublime Text C\Users\Unix\Desktop\writer.py . - Sublime Text O X File Edit Selection Find View Goto Tools Project Preferences Help File Edit Selection Find View Goto Tools Project Preferences Help reader.py writer.py 1 # readers 1 # writers 2 var # global var 4 locktite # ska skydda var 3 var # global var 4 locktite # ska skydda var 5 writerpriolock # ska ge prio till skrivare 5 counter 6 lockcount # ska skydda counter 7 writerpriolock 7 v while (True): writerpriolock.acquire() # <---- en skrivare är här locktite.acquire() 8 9 while (True): writerpriolock.acquire() # <--- två till läsare writerpriolock.release() lockcount.acquire() counter++ if (counter locktite.acquire() lockcount.release() 10 10 11 11 I 12 12 var = something 13 13 14 == 1): locktite.release() writerpriolock.release() 14 15 15 16 17 18 print(var) 19 lockcount.acquire() counter- if (counter locktite.release() lockcount.release() 20 21 22 0): 33= 23 24 25 # <--- en läsare här 14 characters selected UTF-8 Tab Size: 4 Python O Line 14, Column 18 UTF-8 Tab Size: 4 Python 11:59 2021-03-09
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY