#define BOOST_THREAD_USE_LIB
#include <iostream>
#include <boost/thread.hpp>
#include <vector>
using namespace std;
vector<int> someSharedResource;
boost::mutex mutex;
boost::condition_variable_any condition;
void Writer()
{
for (int i = 0; i < 10 ; i++)
{
boost::unique_lock<boost::mutex> locker(mutex);
someSharedResource.push_back(i);
// cout<<boost::this_thread::get_id()<<"\t"<<endl;
condition.notify_all();
condition.wait(mutex);
}
}
void Reader()
{
int counted_items=0;
for( int i =0;i<10;i++)
{
boost::unique_lock<boost::mutex> locker(mutex);
condition.wait(mutex);
cout<<someSharedResource.back()<<"\t"<<boost::this_thread::get_id()<<endl;
counted_items++;
condition.notify_all();
}
}
int main()
{
boost::thread t1(Writer);
boost::thread t2(Reader);
t1.join();
t2.join();
}