【发布时间】:2011-07-17 13:53:16
【问题描述】:
boost::condition cond;
boost::recursive_mutex mutex;
for(;;)
{
D * d = nullptr;
while( cb.pop(d) )
{
}
boost::lock_guard<boost::recursive_mutex> lock( **mutex** );
cond.wait( **mutex** );
}
while(1)
{
getchar();
for( int i = 0 ; i < 1000 ; ++i )
{
cb.push(new D(i));
boost::lock_guard<boost::recursive_mutex> lock( **mutex** );
cond.notify_one();
}
}
我怀疑是互斥体,我只需要互斥体对象?
编辑:
cb 是一个循环缓冲区。 我想实现一种生产者-消费者模式
wait 和 notify_one 是否必须使用相同的互斥锁?
【问题讨论】:
-
你想做什么?什么是cb?为什么会有这些无限循环?