• <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'雙魚 閱讀(1968) 評論(0)  編輯 收藏 引用
            久久精品人人做人人妻人人玩 | 天天影视色香欲综合久久| 久久久久久久尹人综合网亚洲| 九九99精品久久久久久| 久久精品国产亚洲AV不卡| 亚洲AV无码成人网站久久精品大| 国产V亚洲V天堂无码久久久| 94久久国产乱子伦精品免费| 亚洲中文字幕无码久久2020| 26uuu久久五月天| 亚洲精品乱码久久久久久久久久久久| 亚洲成色999久久网站| 亚洲午夜久久久久久噜噜噜| 韩国三级中文字幕hd久久精品 | 亚洲国产天堂久久综合网站| 欧美午夜A∨大片久久 | 色综合久久久久无码专区| 亚洲午夜精品久久久久久人妖| 波多野结衣久久一区二区| 草草久久久无码国产专区| 久久久久亚洲av无码专区导航| 久久精品视频91| 一本一道久久精品综合| 亚洲综合伊人久久大杳蕉| 欧美精品丝袜久久久中文字幕 | 亚洲国产小视频精品久久久三级 | 久久久久99精品成人片欧美| 亚洲国产精品成人AV无码久久综合影院 | 久久久久99精品成人片三人毛片 | 99精品国产99久久久久久97| 久久精品亚洲欧美日韩久久| 亚洲欧美日韩精品久久| 麻豆精品久久久一区二区| 久久国产精品99精品国产| 久久精品国产亚洲AV无码麻豆| 久久精品国产亚洲αv忘忧草| 亚洲欧美精品一区久久中文字幕| 久久无码精品一区二区三区| 久久久WWW成人免费毛片| 合区精品久久久中文字幕一区| 亚洲精品国产综合久久一线|