Skip to content
Snippets Groups Projects
Commit b1c32a4e authored by Thomas Letzgus's avatar Thomas Letzgus
Browse files

Upload New File

parent c2a19bec
No related tags found
No related merge requests found
from buffer import Buffer
import threading
import random
import time
class Consumer:
def __init__(self, buffer_obj):
self.buffer = buffer_obj
def consume(self):
while True:
time.sleep(random.uniform(0.5, 2.0)) # Random interval between checks
with self.buffer.condition:
while self.buffer.empty():
self.buffer.condition.wait() # Wait until buffer is not empty
car = self.buffer.pop()
print("Consumer: Car", car.get_car_id(), "parked out")
if self.buffer.full():
# Buffer was completely full before the withdrawal, wake up all sleeping producers
self.buffer.condition.notify_all()
# Example usage:
buffer = Buffer(size=10) # Assuming buffer is already initialized with a size of 10
consumer = Consumer(buffer)
# Create and start the consumer thread
consumer_thread = threading.Thread(target=consumer.consume)
consumer_thread.start()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment