Welcome to this Bounded Blocking Queue project! π
A classic Producer-Consumer model implemented in Python with full thread safety using locks and condition variables. Perfect for understanding the magic of multithreading and synchronization! π§ββοΈβ¨
- β Thread-safe queue with fixed capacity
- π Uses
threading.Lockandthreading.Conditionto ensure safe concurrent access - π Supports multiple producers and multiple consumers working simultaneously
- π¦ Automatically blocks producers if queue is full and consumers if queue is empty
- π Written in clean, readable Python with detailed comments
- Producers call
put(item)to add data; if full, they wait patiently β³ - Consumers call
get()to retrieve data; if empty, they wait for producers to supply π½οΈ - Synchronization primitives manage access, avoiding race conditions and deadlocks βοΈ
Producer 1 produced: 0 Consumer 1 consumed: 0 Producer 2 produced: 10 Consumer 2 consumed: 10 ... All producers and consumers have finished.
- Add timeout support β° for
put()andget() - Implement an asynchronous version using
asyncioβ‘ - Benchmark performance under different workloads π
- Wrap it into a reusable Python package π¦
Shuai Qian οΌAlex QuinnοΌ
Passionate about data structures, algorithms, and system programming. Always learning, always coding! π‘π»
Feel free to β star this repo if you find it useful or interesting!
Happy coding! ππ