• <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>
            http://www.boost.org/doc/libs/1_35_0/doc/html/thread/synchronization.html

            Mutex概念
            線程同步最基本的是mutex(mutual exclusion的縮寫)。一個互斥體一次只允許一個線程訪問共享區(qū)。當一個線程想要訪問共享區(qū)時,首先要做的就是鎖?。╨ock)互斥體。如果其他的 線程已經(jīng)鎖住了互斥體,那么就必須先等那個線程將互斥體解鎖,這樣就保證了同一時刻只有一個線程能訪問共享區(qū)域。

            Boost.Thread supplies recursive and non-recursive mutexes with exclusive ownership(獨占) semantics, along with a shared ownership (共享) (multiple-reader / single-writer) mutex.
            Boost.Thread supports four basic concepts for lockable objects:

            Lockable,
            exclusive ownership
            TimedLockable,
            Lockable的基礎上加上了timeout
            SharedLockable,
            TimedLockable基礎上,允許shared ownership(同時也支持exclusive)
            This is the standard multiple-reader / single-write model:
            at most one thread can have exclusive ownership, and if any thread does have exclusive ownership, no other threads can have shared or exclusive ownership. Alternatively, many threads may have shared ownership.
            UpgradeLockable,
            SharedLockable基礎上,允許upgradable ownership(同時也支持shared、exclusive)
            This is an extension to the multiple-reader / single-write model provided by the SharedLockable concept:
            a single thread may have upgradable ownership at the same time as others have shared ownership. The thread with upgradable ownership may at any time attempt to upgrade that ownership to exclusive ownership. If no other threads have shared ownership, the upgrade is completed immediately, and the thread now has exclusive ownership, which must be relinquished by a call to unlock(), just as if it had been acquired by a call to lock().

            [注:除Lockable的mutex外,其余的各種復雜mutex還需要更多代碼實踐]

            Each mutex type implements one or more of these concepts, as do the various lock types.

            Lock Types
            boost定義的Lock types為class template,以合適的Lockable object作為模板參數(shù)
            lock_guard
            RAII-style的簡單lock,在ctor中l(wèi)ock,在dtor中unlock
            只支持簡單的Lockable object
            unique_lock
            lock_guard復雜在:不僅提供RAII-style的lock,還允許用戶指定是否在ctor中立即lock,意味著可以指定推遲lock(defer acquiring the lock,通過指定defer_lock_t參數(shù)),直到顯式調(diào)用其lock()方法
            還支持TimedLockable concept,前提是需要lock的Lockable object本身支持
            The member functions of boost::unique_lock are not thread-safe...[注:這句沒看懂。。。]

            shared_lock
            upgrade_lock
            upgrade_to_unique_lock

            [注:目前只用過unique_lock。后面幾種對應于不同需求的lock,從名字就可以直觀看出功能,還未試驗,直接參考api]
            Mutex Types
            Mutex types對應于之前的mutex concepts,目前有:
            Class mutex
            boost::mutex實現(xiàn)了Lockable concept,提供exclusive-ownership mutex.
            At most one thread can own the lock on a given instance of boost::mutex at any time.
            Multiple concurrent calls to lock(), try_lock() and unlock() shall be permitted.

            typedef unique_lock mutex::scoped_lock;

            Typedef try_mutex
            Class timed_mutex
            Class recursive_mutex
            Typedef recursive_try_mutex
            Class recursive_timed_mutex
            Class shared_mutex
            適用于不同需求


            Condition Variables
            The general usage pattern is that one thread locks a mutex and then calls wait on an instance of condition_variable or condition_variable_any. When the thread is woken from the wait, then it checks to see if the appropriate condition is now true, and continues if so. If the condition is not true, then the thread then calls wait again to resume waiting.(中文參考)

            lock is passed to wait()wait() will atomically add the thread to the set of threads waiting on the condition variable, and unlock the mutex. When the thread is woken, the mutex will be locked again before the call to wait returns. This allows other threads to acquire the mutex in order to update the shared data, and ensures that the data associated with the condition is correctly synchronized.

            In the mean time, another thread sets the condition to true, and then calls either notify_one() or notify_all() on the condition variable to wake one waiting thread or all the waiting threads respectively.


            condition_variable_any比condition_variable更通用;condition_variable要求傳給wait()的必須是boost::unique_lock<boost::mutex>類型;condition_variable一般更優(yōu)化

            One-time Initialization
            僅運行一次的例程
            http://www.stlchina.org/twiki/bin/view.pl/Main/BoostThread#5%20%BD%F6%D4%CB%D0%D0%D2%BB%B4%CE%B5%C4%C0%FD%B3%CC
            [注:還未使用過]

            Barriers
            [注:還未使用過]



            posted on 2008-04-29 14:28 frank28_nfls 閱讀(651) 評論(0)  編輯 收藏 引用
             
            国产亚洲欧美成人久久片 | 伊人久久大香线蕉av不卡| 狠狠色丁香久久婷婷综合_中| 无码人妻精品一区二区三区久久久 | 狠色狠色狠狠色综合久久 | 久久久久久综合一区中文字幕| 久久久久久毛片免费看| 色综合久久中文字幕无码 | 久久精品国产亚洲AV无码麻豆| 久久久久亚洲AV成人网人人软件| 狠狠色婷婷久久一区二区| 久久www免费人成看国产片| 久久久久99精品成人片试看| 日日狠狠久久偷偷色综合96蜜桃| 久久精品国产亚洲av麻豆图片 | 久久99精品国产一区二区三区| 一本色道久久99一综合| 久久亚洲国产精品五月天婷| 国产精品久久久久久久久| 久久久亚洲AV波多野结衣| 久久婷婷五月综合成人D啪| 欧美伊香蕉久久综合类网站| 久久久久久毛片免费播放| 国产69精品久久久久久人妻精品| 久久影院久久香蕉国产线看观看| 99久久精品免费国产大片| 精品综合久久久久久888蜜芽| 亚洲精品蜜桃久久久久久| 亚洲中文字幕久久精品无码APP | 亚洲性久久久影院| 久久精品无码一区二区三区免费| 香蕉久久夜色精品国产小说| 丰满少妇人妻久久久久久| 国产69精品久久久久777| 97久久超碰国产精品2021| 97久久综合精品久久久综合| 97精品国产91久久久久久| 久久精品国产亚洲麻豆| 国产精品内射久久久久欢欢| 久久久综合香蕉尹人综合网| 午夜精品久久久内射近拍高清|