• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-6  評論-2  文章-1  trackbacks-0
            一. 線程啟動
                線程的啟動由傳遞一個沒有構造函數的Callable類,之后復制到內存,由最新的線程調用.
            struct callable
            {
                
            void operator()();
            };
            如果該類必須不可復制,那么可以用boost::ref傳遞一個Callable對象的引用到構造中.
            boost::thread copies_are_safe()
            {
                callable x;
                
            return boost::thread(x); //參數為X的一份拷貝
            // x is destroyed, but the newly-created thread has a copy, so this is OK 
            boost::thread oops()
            {
                callable x;
                
            return boost::thread(boost::ref(x)); //參數為X的引用
            // x is destroyed, but the newly-created thread still has a reference
              
            // this leads to undefined behaviour
            線程可以用一個函數或callable對象為參數構造,用boost::bind來實現
            void find_the_question(int the_answer);

            boost::thread deep_thought_2(boost::bind(find_the_question,
            42));
            void print();
            boost::thread t=boost::thread(&print);

            二.線程接合與脫離
            當被銷毀時,線程稱為脫離(detached),當線程為脫離(detached)時,線程繼續執行直到構造函數中函數或callable對象執行完畢,或程式終止.
            void print();
            boost::thread t(
            &print);
            t.join();
            //線程銷毀
            t.join();//線程已經失效,t不指向任何線程,無作用
            std::cout<<boolalpha<<t.joinable()<<std::endl;//print false statement

            線程的脫離可以明確調用boost::detach()函數,這種情況下線程為非現脫離線程(now-detached thread),變為非線程(Not-a-Thread).
            boost::thread::join() //如果線程為中斷(interrupted),引發boost::thread_interrupted異常.
            boost::thread::detach() //不引發異常,如果線程不脫離,線程析構時調用.



            posted on 2009-01-22 10:01 L'雙魚 閱讀(1970) 評論(0)  編輯 收藏 引用
            一本色道久久综合狠狠躁篇| 人妻无码αv中文字幕久久琪琪布| 久久精品无码午夜福利理论片| 无码人妻久久一区二区三区免费 | 狠狠色丁香婷婷综合久久来 | 人人狠狠综合久久亚洲| 欧美性猛交xxxx免费看久久久| 久久久久久精品久久久久| 久久午夜无码鲁丝片| 久久高清一级毛片| 亚洲AV无码久久精品狠狠爱浪潮| 国产精品久久自在自线观看| 久久亚洲国产精品五月天婷| 日韩精品久久久久久免费| 欧美午夜A∨大片久久| 久久精品国产99国产电影网| 精品久久久久成人码免费动漫| 97久久久精品综合88久久| 亚洲精品无码专区久久同性男| 久久亚洲精品中文字幕三区| 久久精品国产清自在天天线| 久久影院午夜理论片无码| 91亚洲国产成人久久精品网址| 伊人久久精品无码av一区| 亚洲精品乱码久久久久久蜜桃| 91久久精品视频| 国产精品久久久福利| 欧美亚洲色综久久精品国产| 伊人久久大香线蕉综合热线| 久久久久久无码国产精品中文字幕| 久久国产精品成人影院| 人妻少妇久久中文字幕一区二区| 久久久久这里只有精品| 四虎国产精品免费久久5151| 久久99国产精品99久久| 国产精品一区二区久久| av午夜福利一片免费看久久| 亚洲精品乱码久久久久久按摩| 亚洲中文字幕无码久久精品1| 久久精品中文字幕一区| 亚洲精品tv久久久久久久久|