• <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
            一. 線程啟動
                線程的啟動由傳遞一個沒有構(gòu)造函數(shù)的Callable類,之后復(fù)制到內(nèi)存,由最新的線程調(diào)用.
            struct callable
            {
                
            void operator()();
            };
            如果該類必須不可復(fù)制,那么可以用boost::ref傳遞一個Callable對象的引用到構(gòu)造中.
            boost::thread copies_are_safe()
            {
                callable x;
                
            return boost::thread(x); //參數(shù)為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)); //參數(shù)為X的引用
            // x is destroyed, but the newly-created thread still has a reference
              
            // this leads to undefined behaviour
            線程可以用一個函數(shù)或callable對象為參數(shù)構(gòu)造,用boost::bind來實現(xiàn)
            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);

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

            線程的脫離可以明確調(diào)用boost::detach()函數(shù),這種情況下線程為非現(xiàn)脫離線程(now-detached thread),變?yōu)榉蔷€程(Not-a-Thread).
            boost::thread::join() //如果線程為中斷(interrupted),引發(fā)boost::thread_interrupted異常.
            boost::thread::detach() //不引發(fā)異常,如果線程不脫離,線程析構(gòu)時調(diào)用.



            posted on 2009-01-22 10:01 L'雙魚 閱讀(1963) 評論(0)  編輯 收藏 引用

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            A级毛片无码久久精品免费| 欧美综合天天夜夜久久| 久久久久久噜噜精品免费直播| 久久久久久午夜成人影院| 国产精品热久久无码av| 激情五月综合综合久久69| 欧美成a人片免费看久久| 久久久www免费人成精品| 久久精品国产亚洲一区二区| 久久e热在这里只有国产中文精品99| 久久se这里只有精品| 亚洲色大成网站www久久九| 大美女久久久久久j久久| 久久久久久精品免费免费自慰| 国产精品久久久久9999| 一本色综合久久| 青青热久久综合网伊人| 一本色道久久综合亚洲精品| Xx性欧美肥妇精品久久久久久| 久久91精品国产91| 久久精品国产欧美日韩| 国产国产成人精品久久| 久久婷婷五月综合国产尤物app| 久久综合综合久久97色| 色综合久久综合中文综合网| 久久精品国产第一区二区| 99麻豆久久久国产精品免费| 亚洲乱码精品久久久久..| 日韩十八禁一区二区久久| 久久影视国产亚洲| 韩国三级大全久久网站| 亚洲AV无码久久| 亚洲国产精品无码久久98| 久久天天躁狠狠躁夜夜不卡| 久久最新免费视频| 国産精品久久久久久久| 国产成人精品久久亚洲高清不卡| AV狠狠色丁香婷婷综合久久| 久久国产亚洲精品无码| 色综合久久无码中文字幕| 欧美va久久久噜噜噜久久|