• <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
            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            常用鏈接

            留言簿(1)

            隨筆檔案

            文章分類

            搜索

            •  

            積分與排名

            • 積分 - 33043
            • 排名 - 610

            最新評論

            閱讀排行榜

            評論排行榜

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

             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 /// 這個是輔助類,能夠保證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)  編輯 收藏 引用
            久久久久国色AV免费看图片| 久久成人国产精品免费软件| 四虎国产精品免费久久久| 精品熟女少妇av免费久久| 四虎国产永久免费久久| 久久无码专区国产精品发布| 亚洲va久久久噜噜噜久久天堂| 大香网伊人久久综合网2020| 久久久久人妻一区二区三区 | 精品国产91久久久久久久| 精品99久久aaa一级毛片| 日韩精品久久无码中文字幕| 青青草原综合久久大伊人导航 | 久久久精品免费国产四虎| 色偷偷88欧美精品久久久| 久久99精品久久久久久动态图| 亚洲国产天堂久久综合| 91久久精品国产成人久久| 精品久久久久久无码中文字幕一区| 久久精品国产精品亚洲下载| 99久久精品国内| 2020久久精品国产免费| 男女久久久国产一区二区三区 | 亚洲中文字幕无码久久2020| 欧美精品丝袜久久久中文字幕 | 久久久久久久女国产乱让韩| 久久天天躁狠狠躁夜夜2020老熟妇 | 人妻无码久久一区二区三区免费| 午夜视频久久久久一区 | 综合网日日天干夜夜久久| 欧美久久亚洲精品| 久久久WWW成人免费毛片| 久久精品成人| 国产精品久久久久久五月尺| 亚洲精品无码久久久久AV麻豆| 久久艹国产| 亚洲国产成人久久精品99| 久久久久久久久66精品片| 蜜桃麻豆www久久国产精品| 人妻无码精品久久亚瑟影视| 日日狠狠久久偷偷色综合96蜜桃|