[英]How can I add boost threads to a vector
I have something like this that is incorect: 我有这样的东西是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 ? 也许我应该在向量中添加指向boost :: thread的指针,但后来我不知道如何添加动态分配的线程,我该怎么做才能使这个工作?
Thank you. 谢谢。
or use vector<shared_ptr<boost::thread>>
with code like: 或使用
vector<shared_ptr<boost::thread>>
代码如下:
vec.push_back(make_shared<boost::thread>(sellTickets, agent, numTickets/numAgents));
or use boost::thread_group
. 或者使用
boost::thread_group
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.