开发者

How can I add boost threads to a vector

开发者 https://www.devze.com 2023-02-19 23:52 出处:网络
I have something like this that is incorect: vector<boost::thread> vec; for(int agent = 1; agent <= numAgents; ++agent)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消