#include "queue1.h"
#include <iostream>
#include <thread>
#include <vector>
#include <atomic>
#include <chrono>
std::atomic<int> c( 0 );
void push_pop( threadsafe_queue<int> & tss)
{
for ( int i=0; i<10000; ++i ) {
tss.push( ++c );
// std::shared_ptr<int> top = tss.wait_and_pop();
// or
int val = 0;
tss.wait_and_pop( val );
}
}
int main()
{
threadsafe_queue<int> tss;
tss.push( 1 );
std::vector<std::thread> threads;
for( unsigned i=0; i<200; ++i ) {
threads.push_back( std::thread( push_pop, std::ref( tss ) ) );
}
for( auto & t : threads ) {
t.join();
}
std::cout << "Stack content: ";
while( !tss.empty() ) {
std::shared_ptr<int> top = tss.wait_and_pop();
std::cout << *top << std::endl;
}
}