• <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年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(1)

            隨筆檔案

            文章分類

            搜索

            •  

            積分與排名

            • 積分 - 33011
            • 排名 - 608

            最新評論

            閱讀排行榜

            評論排行榜

                程序中幾個線程一起往控制臺寫入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 許海斌 閱讀(2660) 評論(0)  編輯 收藏 引用
            国产精品美女久久久m| 久久久久国产精品麻豆AR影院| 久久婷婷五月综合成人D啪 | 久久综合狠狠综合久久| 久久亚洲美女精品国产精品| 久久久无码精品亚洲日韩按摩| 久久精品国产99国产精偷| 日本加勒比久久精品| 无码精品久久久久久人妻中字| 国产精品日韩欧美久久综合| 日韩欧美亚洲综合久久影院Ds| 人妻无码中文久久久久专区| 国产成人久久精品二区三区| 99精品国产免费久久久久久下载| 精品久久久久久成人AV| 伊人久久大香线蕉综合5g| 99久久免费国产精品热| 亚洲&#228;v永久无码精品天堂久久 | 久久国产热这里只有精品| 伊人久久大香线蕉av一区| 色综合合久久天天综合绕视看| 久久久久久久久久久精品尤物 | 亚洲精品tv久久久久久久久| 国产精品久久久99| 激情伊人五月天久久综合| 日本WV一本一道久久香蕉| 久久99精品久久久久久水蜜桃| 久久综合国产乱子伦精品免费| 久久福利资源国产精品999| 久久精品国产亚洲5555| 国产99久久久国产精品~~牛| 国产精品无码久久综合| 中文字幕久久精品无码| 亚洲国产精品无码久久久秋霞2| 色偷偷88欧美精品久久久| 久久精品亚洲欧美日韩久久| 久久香蕉国产线看观看乱码| 天天久久狠狠色综合| 久久久精品午夜免费不卡| 久久国产精品99精品国产987| 狠狠色婷婷综合天天久久丁香 |