<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                博客?`[c++11特性之std::thread--初識](http://blog.csdn.net/wangshubo1989/article/details/49592517 "std::thread")`? 講了std::thread::join和std::thread::detach的用法。今天就再來點深入的。 先看看這個: ~~~ int main() { std::thread t(&thread_function); std::cout << "main thread\n"; // t.join(); t.detach(); t.join(); // Error return 0; } ~~~ **一旦 detached, 就不能再join**? 這個時候總要有新東西出場了:? **joinable()** ~~~ #include <iostream> // std::cout #include <thread> // std::thread void mythread() { // do stuff... } int main() { std::thread foo; std::thread bar(mythread); std::cout << "Joinable after construction:\n" << std::boolalpha; std::cout << "foo: " << foo.joinable() << '\n'; std::cout << "bar: " << bar.joinable() << '\n'; if (foo.joinable()) foo.join(); if (bar.joinable()) bar.join(); std::cout << "Joinable after joining:\n" << std::boolalpha; std::cout << "foo: " << foo.joinable() << '\n'; std::cout << "bar: " << bar.joinable() << '\n'; return 0; } ~~~ 之前的例子中, 我們都是使用的普通的函數. 我們本可以使用更多,尤其你要牢記的就是c++是一個面向對象。 ~~~ #include <iostream> #include <thread> class MyFunctor { public: void operator()() { std::cout << "functor\n"; } }; int main() { MyFunctor fnctor; std::thread t(fnctor); std::cout << "main thread\n"; t.join(); return 0; } ~~~ 上面的代碼,我創建了一個函數對象,把它付給一個線程任務 也許你會像下面這樣寫: ~~~ std::thread t(MyFunctor()); ~~~ 但是,編譯時通不過的,你應該這樣寫: ~~~ std::thread t((MyFunctor())); ~~~ **必須加一個 () 來封裝 MyFunctor().**
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看