Skip to content

Instantly share code, notes, and snippets.

@PolarNick239
PolarNick239 / blocking_queue.h
Last active September 11, 2022 12:30
C++ concurrent blocking queue with limited size (based on boost condition_variable)
#include <queue>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
// Based on https://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html
template<typename Data>
class BlockingQueue {
private:
std::queue<Data> queue;
mutable boost::mutex queue_mutex;
@thelinked
thelinked / LockingQueue.hpp
Last active May 28, 2025 11:22
C++11 blocking queue using the standard library.
#pragma once
#include <queue>
#include <mutex>
#include <condition_variable>
template<typename T>
class LockingQueue
{
public:
void push(T const& _data)