How to make boost::thread_group execute a fixed number of parallel threads

后端 未结 4 942
梦如初夏
梦如初夏 2020-12-09 18:59

This is the code to create a thread_group and execute all threads in parallel:

boost::thread_group group;
for (int i = 0; i < 15; ++i)
    group.create_th         


        
4条回答
  •  再見小時候
    2020-12-09 19:08

    I think you are looking for a thread_pool implementation, which is available here.

    Additionally I have noticed that if you create a vector of std::future and store futures of many std::async_tasks in it and you do not have any blocking code in the function passed to the thread, VS2013 (atleast from what I can confirm) will launch exactly the appropriate no of threads your machine can handle. It reuses the threads once created.

提交回复
热议问题