Single producer / 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;
}
Single producer / single consumer wait-free ring queue.
bool Enqueue(const T &item)
Enqueue an item into the ring queue (single producer thread method)
bool Dequeue(T &item)
Dequeue an item from the ring queue (single consumer thread method)
Single producer / single consumer wait-free ring queue definition.