Multiple producers / single consumer wait-free ring queue example
#include <iostream>
#include <string>
#include <thread>
int main(int argc, char** argv)
{
std::cout << "Please enter some integer numbers. Enter '0' to exit..." << std::endl;
auto consumer = std::thread([&queue]()
{
int item;
do
{
std::this_thread::yield();
std::cout << "Your entered number: " << item << std::endl;
} while (item != 0);
});
std::string line;
while (getline(std::cin, line))
{
int item = std::stoi(line);
std::this_thread::yield();
if (item == 0)
break;
}
consumer.join();
return 0;
}
Multiple producers / single consumer wait-free ring queue.
bool Dequeue(T &item)
Dequeue an item from the ring queue (single consumer threads method)
bool Enqueue(const T &item)
Enqueue an item into the ring queue (multiple producers threads method)
Multiple producers / single consumer wait-free ring queue definition.