Here are some pointers and some sample code:
std::queue<int> data;
boost::mutex access;
boost::condition cond;
bool empty()
{
return data.empty();
}
void thread1()
{
while (true)
{
boost::mutex::scoped_lock lock(access);
cond.wait(lock, empty);
while (!empty())
{
int datum=data.top();
data.pop();
}
}
}
void thread2()
{
while (true)
{
boost::mutex::scoped_lock lock(access);
data.push_back(1);
cond.notify_one();
}
}
int main()
{
boost::thread t1(thread1);
boost::thread t2(thread2);
t1.join();
t2.join();
return 0;
}
queue STL threads, Boost. boost - , ++ .
, . , . , , - .