【发布时间】:2011-10-22 22:56:25
【问题描述】:
我编写了一个类似于以下结构的多线程程序(我省略了互斥锁和无关代码),当从线程调用时,它会阻塞对boost::thread_group.add_thread() 的调用。有没有办法解决这个问题,所以调用不会阻塞?
boost::thread_group group;
void threaded_function2()
{
}
void threaded_function()
{
if( condition)
{
boost::thread *t3 = new boost::thread( boost::bind( &threaded_function2));
group.add_thread( t3); // <-- Blocks on this call
}
}
int main()
{
boost::thread *t1 = new boost::thread( boost::bind( &threaded_function));
boost::thread *t2 = new boost::thread( boost::bind( &threaded_function));
group.add_thread( t1);
group.add_thread( t2);
group.join_all();
return 0;
}
谢谢大家。
【问题讨论】:
标签: c++ multithreading boost boost-thread