我如何提升线程添加到载体 [英] How can I add boost threads to a vector
本文介绍了我如何提升线程添加到载体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的事情是incorect:
I have something like this that is incorect:
vector<boost::thread> vec;
for(int agent = 1; agent <= numAgents; ++agent)
{
boost::thread agentThread(sellTickets, agent, numTickets/numAgents);
vec.push_back(agentThread);
}
也许我应该补充的指针,以提高::线程向量,但我不知道如何添加动态分配的线程,我应该怎么做才能使这项工作?
Maybe i should add pointers to boost::thread in the vector, but then I don't know how to add dynamic allocated threads, how should I do to make this work ?
感谢您。
推荐答案
- 您必须拥有,以便让你的code的工作支持移动语义编译器,
-
或使用
矢量&lt;&的shared_ptr LT;提高::线程&GT;&GT;
与code,如:
vec.push_back(make_shared<boost::thread>(sellTickets, agent, numTickets/numAgents));
或使用的boost :: thread_group
。
这篇关于我如何提升线程添加到载体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文