<bdo id='SbX66'></bdo><ul id='SbX66'></ul>

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

    3. <tfoot id='SbX66'></tfoot>
    4. <legend id='SbX66'><style id='SbX66'><dir id='SbX66'><q id='SbX66'></q></dir></style></legend>

      1. 未存储返回值时,std::async 不会产生新线程

        时间:2023-05-23
          <bdo id='00U6w'></bdo><ul id='00U6w'></ul>

          <legend id='00U6w'><style id='00U6w'><dir id='00U6w'><q id='00U6w'></q></dir></style></legend>

          <small id='00U6w'></small><noframes id='00U6w'>

              <tbody id='00U6w'></tbody>
            <tfoot id='00U6w'></tfoot>
            <i id='00U6w'><tr id='00U6w'><dt id='00U6w'><q id='00U6w'><span id='00U6w'><b id='00U6w'><form id='00U6w'><ins id='00U6w'></ins><ul id='00U6w'></ul><sub id='00U6w'></sub></form><legend id='00U6w'></legend><bdo id='00U6w'><pre id='00U6w'><center id='00U6w'></center></pre></bdo></b><th id='00U6w'></th></span></q></dt></tr></i><div id='00U6w'><tfoot id='00U6w'></tfoot><dl id='00U6w'><fieldset id='00U6w'></fieldset></dl></div>
                1. 本文介绍了未存储返回值时,std::async 不会产生新线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  考虑我有lamba foo 它只做一些事情并且不需要返回任何东西.当我这样做时:

                  Consider I have lamba foo which just does some stuff and doesn't need to return anything. When I do this:

                  std::future<T> handle = std::async(std::launch::async, foo, arg1, arg2);
                  

                  一切正常,lamba 将在新线程中生成.但是,当我不存储 std::async 返回的 std::future 时,foo 将在主线程中运行并阻塞它.>

                  Everything runs fine and the lamba will be spawned in a new thread. However, when I don't store the std::future which the std::async returns, the foo will be run in the main thread and block it.

                  std::async(std::launch::async, foo, arg1, arg2);
                  

                  我在这里遗漏了什么?

                  推荐答案

                  来自 just::thread 文档:

                  如果策略是 std::launch::async 然后在它自己的线程上运行 INVOKE(fff,xyz...).当该线程完成时,返回的 std::future 将准备就绪,并将保存函数调用抛出的返回值或异常.与返回的 std::future 的异步状态相关联的最后一个 future 对象的析构函数应阻塞,直到 future 准备好.

                  If policy is std::launch::async then runs INVOKE(fff,xyz...) on its own thread. The returned std::future will become ready when this thread is complete, and will hold either the return value or exception thrown by the function invocation. The destructor of the last future object associated with the asynchronous state of the returned std::future shall block until the future is ready.

                  std::async(std::launch::async, foo, arg1, arg2);
                  

                  返回的 future 不会在任何地方赋值,它的析构函数会阻塞直到 foo 完成.

                  The returned future is not assigned anywhere and its destructor blocks until foo finishes.

                  这篇关于未存储返回值时,std::async 不会产生新线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:需要对同步与异步 asio 操作进行一些说明 下一篇:boost::asio + std::future - 关闭套接字后访问冲突

                  相关文章

                  最新文章

                2. <small id='rNp2f'></small><noframes id='rNp2f'>

                  <i id='rNp2f'><tr id='rNp2f'><dt id='rNp2f'><q id='rNp2f'><span id='rNp2f'><b id='rNp2f'><form id='rNp2f'><ins id='rNp2f'></ins><ul id='rNp2f'></ul><sub id='rNp2f'></sub></form><legend id='rNp2f'></legend><bdo id='rNp2f'><pre id='rNp2f'><center id='rNp2f'></center></pre></bdo></b><th id='rNp2f'></th></span></q></dt></tr></i><div id='rNp2f'><tfoot id='rNp2f'></tfoot><dl id='rNp2f'><fieldset id='rNp2f'></fieldset></dl></div>

                    <legend id='rNp2f'><style id='rNp2f'><dir id='rNp2f'><q id='rNp2f'></q></dir></style></legend>
                    1. <tfoot id='rNp2f'></tfoot>
                        <bdo id='rNp2f'></bdo><ul id='rNp2f'></ul>