Skip to content

The BlockQueue pattern is a thread-safe queue implementation that allows multiple threads to push and pop elements concurrently. It provides synchronized access to the underlying queue, ensuring that no data race occurs between threads.

License

Notifications You must be signed in to change notification settings

BardiParsi/BlockQueue

Repository files navigation

Block Queue Pattern

The BlockQueue pattern is a thread-safe queue implementation designed for concurrent multi-threaded environments. It ensures synchronized access to the underlying queue, preventing data races and ensuring thread safety. This implementation allows multiple threads to push and pop elements from the queue concurrently.

Features

  • Thread Safety: Utilizes mutex and condition variables to ensure safe concurrent access.
  • Blocking Operations: Supports blocking push and pop operations, ensuring that threads wait when the queue is full or empty.
  • Dynamic Size: Allows the specification of a maximum size for the queue, providing flexibility in resource utilization.
  • Simple Integration: Easy-to-use interface for integrating into multi-threaded applications.

Implementation

BlockQueue.h: Header file containing the implementation of the BlockQueue pattern. Logger.h and Logger.cpp: Implementation of a simple logging utility for console output.

Dependencies

C++20 or later

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

Usage

#include "BlockQueue.h"

// Example usage
BlockQueue<int> queue(10); // Create a queue with a maximum size of 10

// Push elements into the queue
queue.push(10);
queue.push(20);

// Pop elements from the queue
int item = queue.front();
queue.pop();

About

The BlockQueue pattern is a thread-safe queue implementation that allows multiple threads to push and pop elements concurrently. It provides synchronized access to the underlying queue, ensuring that no data race occurs between threads.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages