我有这个给出错误的代码:
error this boost::lock_error
error this boost::lock_error
error this boost::lock_error
error this boost::lock_error
error this boost::lock_error
由于我不知道错误在哪里,我将尝试复制代码:
主要的
boost::tuple<ppa::Node*, ppa::Node*, ppa::Node*, bool> tuple = dups.back();
ppa::Node *n = boost::get<0>(tuple);
cout << "creating other threads" << endl;
for ( int i = 0; i < 5; ++i )
{
cout << "making thread " << i << endl;
g.create_thread( boost::bind( threaded_function, boost::ref(mf),
boost::ref(n) ));
}
线程
void threaded_function(Model_factory &mf, ppa::Node *root)
{
try
{
while(true)
{
boost::mutex::scoped_lock lock(result_mutex);
if(wait.empty())
{
lock.unlock();
break;
}
else
{
lock.lock();
if(!running_jobs.empty())
{
cout << "vector wait size = " << wait.size() << "\n";
cout << "running size = " << running_jobs.size() << "\n";
cout << "done size = " << done.size() << "\n";
boost::tuple<ppa::Node*, ppa::Node*, ppa::Node*, bool> tuple;
tuple = running_jobs.back();
running_jobs.pop_back();
...
}
...
}
...
}
}
catch (boost::lock_error& le)
{
cout << "error this " << le.what() << endl;
}
}
该代码用于我尝试并行执行的对齐程序中,它在不同的线程中一一对齐元组,直到等待列表(向量等待)为空。谢谢。我做了一些事情,我lock.unlock()
在每个 if 和 else 之前都放了一个,现在它正在工作,但是为什么?