fifo2.cpp 566 Bytes
#include <deque>
#include <list>
#include <iostream>
#include <thread>
#include <mutex>
#include <unistd.h>
#include <chrono>

using namespace std;

std::deque<unsigned int> FIFO;
std::mutex FIFO_lock;

void process()
{
  while(1)
  {
    std::unique_lock l(FIFO_lock);
    if(!FIFO.empty())
    {
        cout << FIFO.back() << endl;
        FIFO.pop_back();
    }
  }
}

int main()
{
  std::thread t(process);
  unsigned int i = 0;
  while(1)
  {
   {
     std::unique_lock l(FIFO_lock);
     FIFO.push_front(i++);
   }
   std::this_thread::sleep_for(10ms);
  }
}