Reputation: 20058
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.
Upvotes: 8
Views: 4599
Reputation: 72469
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
.
Upvotes: 24