• <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>
            隨筆 - 7  文章 - 6  trackbacks - 0
            <2009年1月>
            28293031123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(1)

            隨筆檔案

            文章分類

            搜索

            •  

            積分與排名

            • 積分 - 33041
            • 排名 - 610

            最新評論

            閱讀排行榜

            評論排行榜

                程序中幾個(gè)線程一起往控制臺寫入log_info,但是可以很清楚的看到begin or write_process不會同時(shí)連續(xù)的出現(xiàn),而且在begin of write_process和end of write_process之間肯定不會出現(xiàn)begin of read_process或者end of read_process。但是begin of read_process卻會在控制臺上連續(xù)出現(xiàn),這說明在同一時(shí)刻只有一個(gè)write_prcess在運(yùn)行,但是wrte_process沒有運(yùn)行的時(shí)候,會有多個(gè)read_process并發(fā)運(yùn)行。

             1 #include <iostream>
             2 
             3 #include <boost/thread/thread.hpp>
             4 #include <boost/thread/shared_mutex.hpp>
             5 
             6 using namespace std;
             7 using namespace boost;
             8 
             9 boost::shared_mutex shr_mutex;
            10 
            11 /// 這個(gè)是輔助類,能夠保證log_info被完整的輸出
            12 class safe_log {
            13 public:
            14     static void log(const std::string& log_info) {
            15         boost::mutex::scoped_lock lock(log_mutex);
            16         cout << log_info << endl;
            17     }
            18 
            19 private:
            20     static boost::mutex log_mutex;
            21 };
            22 
            23 boost::mutex safe_log::log_mutex;
            24 
            25 void write_process() {
            26     shr_mutex.lock();
            27     safe_log::log("begin of write_process");
            28     safe_log::log("end of write_process");
            29     shr_mutex.unlock();
            30 }
            31 
            32 void read_process() {
            33     shr_mutex.lock_shared();
            34     safe_log::log("begin of read_process");
            35     safe_log::log("end of read_process");
            36     shr_mutex.unlock_shared();
            37 }
            38 
            39 int main() {
            40 
            41     thread_group threads;
            42     for (int i = 0; i < 10++ i) {
            43         threads.create_thread(&write_process);
            44         threads.create_thread(&read_process);
            45     }
            46 
            47     threads.join_all();
            48 
            49     ::system("PAUSE");
            50 
            51     return 0;
            52 }

            posted on 2009-01-21 13:58 許海斌 閱讀(2665) 評論(0)  編輯 收藏 引用

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


            久久热这里只有精品在线观看| 国产精品久久久久影院色| 久久久精品人妻一区二区三区四| 亚洲精品无码久久久久AV麻豆| 青青草原综合久久大伊人导航| 免费精品久久天干天干| 久久综合九色综合网站| 久久久久无码国产精品不卡| 久久人人爽人人爽AV片| 久久九九精品99国产精品| 四虎国产精品成人免费久久| 亚洲va久久久噜噜噜久久| 99热精品久久只有精品| 亚洲精品乱码久久久久久蜜桃不卡 | 综合久久久久久中文字幕亚洲国产国产综合一区首| 久久精品国产第一区二区三区 | 欧美日韩中文字幕久久久不卡| 97精品依人久久久大香线蕉97| 久久久久一本毛久久久| 99久久国产免费福利| 国产精品99久久久久久宅男| 伊人久久国产免费观看视频| 久久综合九色综合精品| 久久99精品久久久大学生| 久久人妻无码中文字幕| 日韩精品久久无码人妻中文字幕 | 伊人色综合久久天天人手人婷 | 久久这里只精品99re66| 久久久久亚洲AV无码专区桃色| 亚洲综合久久夜AV | 亚洲欧美伊人久久综合一区二区| 久久精品国产亚洲AV久| 国产成人精品久久二区二区| 亚洲欧美日韩精品久久亚洲区| 久久久久久久久波多野高潮| a高清免费毛片久久| 亚洲精品美女久久久久99小说| 久久久久久亚洲Av无码精品专口| 国内精品久久久久久久亚洲 | 国产女人aaa级久久久级| 久久久久亚洲av成人网人人软件|