我有这段代码:
std::unique_lock<std::mutex> lock(m_mutex);
for(;;)
{
// wait for input notification
m_event.wait(lock);
// if there is an input pin doesn't have any data, just wait
for(DataPinIn* ptr:m_in_ports)
if(ptr->m_data_dup==NULL)
continue;
// do work
Work(&m_in_ports,&m_out_ports);
// this might need a lock, we'll see
for(DataPinIn* ptr:m_in_ports)
{
// reduce the data refcnt before we lose it
ptr->FreeData();
ptr->m_data_dup=NULL;
std::cout<<"ptr:"<<ptr<<"set to 0\n";
}
}
其中m_event是一个condition_variable。它等待来自另一个线程的通知,然后做一些工作。但是我发现这只是第一次成功并且它永远阻塞在m_event.wait(lock)上,无论m_event.notify_one()被调用多少次。我应该如何解决这个问题?
提前致谢。