#include <condition_variable>
#include <iostream>
#include <mutex>
#include <thread>
int main(int, const char *[]) {
std::mutex m;
std::condition_variable cv;
std::thread producer([&] {
for (int i = 0; i < 32; ++i) {
std::unique_lock<std::mutex> lk(m);
cv.wait(lk, [&buf] {
return !buf.
full(); });
std::cerr << "Failed to push_back" << std::endl;
}
cv.notify_one();
}
});
std::thread consumer([&] {
for (int i = 0; i < 32; ++i) {
std::unique_lock<std::mutex> lk(m);
cv.wait(lk, [&] {
return !buf.
empty(); });
std::cout << buf.
front() << std::endl;
std::cerr << "Failed to pop_front" << std::endl;
}
cv.notify_one();
}
});
producer.join();
consumer.join();
return 0;
}
Implements a fixed-size double ended queue.
bool pop_front()
Removes the first element from the RingBuffer.
bool push_back(Arg &&value)
Inserts a new element at the end of the RingBuffer.
bool full() const BOXES_NOTHROW
Returns true if the RingBuffer is full.
T & front()
Returns the first element in the queue.
bool empty() const BOXES_NOTHROW
Returns true if the RingBuffer is empty.
Implements a fixed-size double-ended queue.