Question: Suppose N communicating processes share 3 transmission lines, A, B, C. Before using a transmission line, a process calls request(), which returns the identity of
Suppose N communicating processes share 3 transmission lines, A, B, C. Before using a transmission line, a process calls request(), which returns the identity of a free line. After using the line, the process returns it by calling done(line). Complete the implementation below! You do not need to be concerned about fairness among transmission lines, but assuming fairness of the semaphores, your solutions should not starve a communicating process.
In python 3.6, complete the code below:
from threading import Thread, Semaphore from time import sleep from sys import stdout from random import randint
N = 8
# YOUR CODE HERE # raise NotImplementedError() class Communicating(Thread): def __init__(self, i): self.i = i; super().__init__() def run(self): while True: sleep(randint(0, 6)) line = request(); stdout.write(str(self.i) + ' communicating on ' + str(line) + ' '); sleep(randint(0, 3)) stdout.write(str(self.i) + ' done '); done(line)
for i in range(N): Communicating(i).start()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
