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 ?
Thank you.
- You must have a compiler with move-semantics supported in order to make your code work,
or use
vector<shared_ptr<boost::thread>>
with code like:vec.push_back(make_shared<boost::thread>(sellTickets, agent, numTickets/numAgents));
or use
boost::thread_group
.
精彩评论