• <bdo id='YxYus'></bdo><ul id='YxYus'></ul>
        <i id='YxYus'><tr id='YxYus'><dt id='YxYus'><q id='YxYus'><span id='YxYus'><b id='YxYus'><form id='YxYus'><ins id='YxYus'></ins><ul id='YxYus'></ul><sub id='YxYus'></sub></form><legend id='YxYus'></legend><bdo id='YxYus'><pre id='YxYus'><center id='YxYus'></center></pre></bdo></b><th id='YxYus'></th></span></q></dt></tr></i><div id='YxYus'><tfoot id='YxYus'></tfoot><dl id='YxYus'><fieldset id='YxYus'></fieldset></dl></div>
      1. <legend id='YxYus'><style id='YxYus'><dir id='YxYus'><q id='YxYus'></q></dir></style></legend><tfoot id='YxYus'></tfoot>

        <small id='YxYus'></small><noframes id='YxYus'>

      2. 如何让 boost::thread_group 执行固定数量的并行线程

        How to make boost::thread_group execute a fixed number of parallel threads(如何让 boost::thread_group 执行固定数量的并行线程)
        <i id='ZmrTZ'><tr id='ZmrTZ'><dt id='ZmrTZ'><q id='ZmrTZ'><span id='ZmrTZ'><b id='ZmrTZ'><form id='ZmrTZ'><ins id='ZmrTZ'></ins><ul id='ZmrTZ'></ul><sub id='ZmrTZ'></sub></form><legend id='ZmrTZ'></legend><bdo id='ZmrTZ'><pre id='ZmrTZ'><center id='ZmrTZ'></center></pre></bdo></b><th id='ZmrTZ'></th></span></q></dt></tr></i><div id='ZmrTZ'><tfoot id='ZmrTZ'></tfoot><dl id='ZmrTZ'><fieldset id='ZmrTZ'></fieldset></dl></div>
            <bdo id='ZmrTZ'></bdo><ul id='ZmrTZ'></ul>
          • <legend id='ZmrTZ'><style id='ZmrTZ'><dir id='ZmrTZ'><q id='ZmrTZ'></q></dir></style></legend>

                <small id='ZmrTZ'></small><noframes id='ZmrTZ'>

                <tfoot id='ZmrTZ'></tfoot>
                    <tbody id='ZmrTZ'></tbody>
                  本文介绍了如何让 boost::thread_group 执行固定数量的并行线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是创建thread_group并并行执行所有线程的代码:

                  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_thread(aFunctionToExecute);
                  group.join_all();
                  

                  此代码将一次执行所有线程.我想要做的是并行执行它们,但最多 4 个.当 on 终止时,将执行另一个,直到没有更多要执行为止.

                  This code will execute all threads at once. What I want to do is to execute them all but 4 maximum in parallel. When on is terminated, another one is executed until there are no more to execute.

                  推荐答案

                  另一个更有效的解决方案是让每个线程在完成时回调到主线程,主线程上的处理程序可以启动一个新线程每一次.这可以防止对 timed_join 的重复调用,因为在触发回调之前主线程不会执行任何操作.

                  Another, more efficient solution would be to have each thread callback to the primary thread when they are finished, and the handler on the primary thread could launch a new thread each time. This prevents the repetitive calls to timed_join, as the primary thread won't do anything until the callback is triggered.

                  这篇关于如何让 boost::thread_group 执行固定数量的并行线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                  Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                  How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                  What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                  Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                  How boost auto-linking makes choice?(boost自动链接如何做出选择?)
                  • <tfoot id='pcdgf'></tfoot>
                      <tbody id='pcdgf'></tbody>

                      • <i id='pcdgf'><tr id='pcdgf'><dt id='pcdgf'><q id='pcdgf'><span id='pcdgf'><b id='pcdgf'><form id='pcdgf'><ins id='pcdgf'></ins><ul id='pcdgf'></ul><sub id='pcdgf'></sub></form><legend id='pcdgf'></legend><bdo id='pcdgf'><pre id='pcdgf'><center id='pcdgf'></center></pre></bdo></b><th id='pcdgf'></th></span></q></dt></tr></i><div id='pcdgf'><tfoot id='pcdgf'></tfoot><dl id='pcdgf'><fieldset id='pcdgf'></fieldset></dl></div>
                        <legend id='pcdgf'><style id='pcdgf'><dir id='pcdgf'><q id='pcdgf'></q></dir></style></legend>
                        • <bdo id='pcdgf'></bdo><ul id='pcdgf'></ul>
                          1. <small id='pcdgf'></small><noframes id='pcdgf'>