Skip to content

AlexQuinn-Analytics/thread-safe-producer-consumer-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ› οΈ Thread-Safe Producer-Consumer Queue πŸ§΅πŸ”„

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! πŸ§™β€β™‚οΈβœ¨


🎯 Project Highlights

  • βœ… Thread-safe queue with fixed capacity
  • πŸ”’ Uses threading.Lock and threading.Condition to 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

🧩 How It Works

  • 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 βš”οΈ

πŸ§‘β€πŸ’» Example Output Snippet

Producer 1 produced: 0 Consumer 1 consumed: 0 Producer 2 produced: 10 Consumer 2 consumed: 10 ... All producers and consumers have finished.


πŸš€ Future Ideas

  • Add timeout support ⏰ for put() and get()
  • Implement an asynchronous version using asyncio ⚑
  • Benchmark performance under different workloads πŸ“Š
  • Wrap it into a reusable Python package πŸ“¦

🀝 About the Author

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! πŸŽ‰πŸ

About

A thread-safe bounded blocking queue in Python implementing the classic producer-consumer model using locks and condition variables for synchronized multi-threaded operations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages