The required source file is concurrent_queue.hpp
. All you need to do is just including the single file.
#include "concurrent_queue.hpp"
// for convenience
using lime62::concurrent_queue;
concurrent_queue
provides similar interfaces to std::queue
.
auto pop_task = [](concurrent_queue<int>* q) {
try {
std::cout << "It waits until something is pushed in the queue.\n";
int v;
q->front_pop(v);
std::cout << "Got a value(" << v << ")\n";
} catch (std::runtime_error re) {
std::cout << re.what() << std::endl;
}
};
concurrent_queue<int> queue;
std::thread t(pop_task, &queue);
std::this_thread::sleep_for(std::chrono::seconds(3));
std::cout << "Pushed a value in the queue.\n";
queue.push(1);
t.join();
Execute following script to compile examples. (tested on gcc 4.8)
git clone https://github.com/jlim262/concurrent_queue.git
cd concurrent_queue
mkdir build
cd build
cmake ..
make