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

Upload New File

parent c2a19bec
No related branches found
No related tags found
No related merge requests found
import threading
class Buffer:
def __init__(self, size):
self.size = size
self.buffer = []
self.mutex = threading.Lock()
self.condition = threading.Condition(self.mutex)
def push(self, item):
if len(self.buffer) == self.size:
raise ValueError("Buffer is full")
with self.condition:
self.buffer.append(item)
self.condition.notify()
def pop(self):
if len(self.buffer) == 0:
raise ValueError("Buffer is empty")
with self.condition:
item = self.buffer.pop(0)
self.condition.notify()
return item
def full(self):
return len(self.buffer) == self.size
def empty(self):
return len(self.buffer) == 0
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