Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sharing Transmission Lines Suppose N communicating processes share 3 transmission lines, A, B, C . Before using a transmission line, a process calls request() ,

Sharing Transmission Lines

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.

Complete the Python implementation 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

What is organizational flattening? Why is it practiced?

Answered: 1 week ago

Question

What is the environment we are trying to create?

Answered: 1 week ago

Question

How would we like to see ourselves?

Answered: 1 week ago