Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are asked to implement a producer and a simple scheduler for N consumers. The producer and the consumers are represented as threads. The producer

You are asked to implement a producer and a simple scheduler for N consumers. The producer and the consumers are represented as threads. The producer thread produces  different integer numbers and put them in a queue. Design a simple scheduler that will handle the synchronization of the consumer threads. The scheduler should make sure that only one consumer at a time consumes the integer by printing it on the screen. The other consumers should sleep for some time while the thread consumer is consuming. When a thread wakes up, it tries to consume an integer from the queue. Make sure that all consumers get a chance to consume a number. No consumer should make the other ones starve. The producer should not stop producing numbers. 


Your program should have one command-line argument, which specifies the number N of threads. When the program starts, it creates N+1 threads that place themselves in a thread pool. The main thread issues the initial notification to the producer thread to start producing integers and then notify the scheduler to start doing its job as described above by ensuring that the N consumer threads have a chance to consume numbers.

Step by Step Solution

3.41 Rating (148 Votes )

There are 3 Steps involved in it

Step: 1

the implementation of the producer and scheduler for N consumers IN PYTHON import threading import time import queue def producerqueue while True num randomrandint1 100 queueputnum printfProducer Prod... 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

Programming Language Pragmatics

Authors: Michael L. Scott

4th Edition

0124104096, 978-0124104099

More Books

Students also viewed these Operating System questions

Question

Experience these concepts in a management simulation. LO9

Answered: 1 week ago