Question: 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.
Step by Step Solution
3.41 Rating (148 Votes )
There are 3 Steps involved in it
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... View full answer
Get step-by-step solutions from verified subject matter experts
