青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

沒畫完的畫

喂馬 劈柴 BBQ~
posts - 37, comments - 55, trackbacks - 0, articles - 0
  C++博客 ::  :: 新隨筆 :: 聯系 :: 聚合  :: 管理

history:
08.08.27   修改部份翻譯不當的地方   網友 wangk ; free2000fly  修改

MSDN中關于信號量的解釋如下:
{注:在某些書籍中 Semaphore Objects 翻譯為“信標”,有些則翻譯為“信號量”,本文均稱為“信號量”}
信號量(Semaphore Objects)
A semaphore object is a synchronization object that maintains a count between zero and a specified maximum value. The count is decremented each time a thread completes a wait for the semaphore object and incremented each time a thread releases the semaphore.
信號量是維護0到指定最大值之間的計數器的同步對象.當線程完成一次信號量的等待時,計數器自減1,當線程釋放信號量對象時,計數器自增1
{信號量用于對資源進行計數,它包括了
1、帶符號的數值 保存最大的資源數
2、帶符號的數值 保存當前可用的資源數
}

When the count reaches zero, no more threads can successfully wait for the semaphore object state to become signaled.  The state of a semaphore is set to signaled when its count is greater than zero, and nonsignaled when its count is zero.
當計數器為0時,不會再有其它線程等待信號量為受信狀態.計數器的值大于0時信號量對象受信,等于0時便不會受信.

The semaphore object is useful in controlling a shared resource that can support a limited number of users.
信號量對象用于支持有限用戶的共享資源控制

It acts as a gate that limits the number of threads sharing the resource to a specified maximum number.
它可以作為限制線程共享資源最大值的一種方法

For example, an application might place a limit on the number of windows that it creates. 
It uses a semaphore with a maximum count equal to the window limit, decrementing the count whenever a window is created and incrementing it whenever a window is closed. The application specifies the semaphore object in call to one of the wait functions before each window is created. When the count is zero — indicating that the window limit has been reached — the wait function blocks execution of the window-creation code.

例如,一個應用程序限制它所創建的窗體.把信號量的最大值設置為窗體個數的最大值, 當窗體創建時,信號量的值減少,當窗體關閉時,信號量的值增加.應用程序在窗體創建時調用 Wait 系列API函數.當計數為0時,證明窗體個數已經達到極限, wait 系列函數會阻塞創建窗體的代碼

A thread uses the CreateSemaphore or CreateSemaphoreEx function to create a semaphore object. The creating thread specifies the initial count and the maximum value of the count for the object. The initial count must be neither less than zero nor greater than the maximum value.
The creating thread can also specify a name for the semaphore object. Threads in other processes can open a handle to an existing semaphore object by specifying its name in a call to the OpenSemaphore function.

線程可以使用 CreateSemaphore 或 CreateSemaphoreEx 創建信號量對象
創建信號量的線程需要指出信號量的初始值和最大值
初始值必須大于0且不大于所指定的最大值
創建的線程同樣可以為信號量指定一個名字
其它進程的線程可以通過這個名字,然后調用 OpenSemaphore() 來打開已經存在的信號量對象

For additional information about names for mutex, event, semaphore, and timer objects, see Interprocess Synchronization.
If more than one thread is waiting on a semaphore, a waiting thread is selected. Do not assume a first-in, first-out (FIFO) order. External events such as kernel-mode APCs can change the wait order.

如果多于一條線程在等待信號量對象,wait 返回的那條線程并不會遵循先進先出(FIFO)的順序,因為內核模式可能改變它的順序。

Each time one of the wait functions returns because the state of a semaphore was set to signaled, the count of the semaphore is decreased by one. The ReleaseSemaphore function increases a semaphore's count by a specified amount. The count can never be less than zero or greater than the maximum value.
每次信號量受信,wait 系列函數就會返回, 同時計數會減1,
ReleaseSemaphore() 函數用來增加信號量的計數值,這個值永遠大于等于0且小于等于指定的最大值

The initial count of a semaphore is typically set to the maximum value. The count is then decremented from that level as the protected resource is consumed. Alternatively, you can create a semaphore with an initial count of zero to block access to the protected resource while the application is
being initialized. After initialization, you can use ReleaseSemaphore to increment the count to the maximum value.

信號量的初始值通常被設置為最大值,當被保護的資源被消耗時,其計數值會被減少。或者,你可以在創建信號值時把初始值指定為 0, 應用程序初始化時,保護資源會阻塞, 初始化后,你可以調用 ReleaseSemaphore  來增加信號量的計數值

A thread that owns a mutex object can wait repeatedly for the same mutex object to become signaled without its execution becoming blocked. A thread that waits repeatedly for the same semaphore object, however, decrements the semaphore's count each time a wait operation is completed; the thread is blocked when the count gets to zero. Similarly, only the thread that owns a mutex can successfully call the ReleaseMutex function, though any thread can use ReleaseSemaphore to increase the count of a semaphore object.

一條線程可以反復地等待 mutex 對象,在它受信前,不會去執行阻塞的代碼塊
同樣,一條線程也可以反復地等待 信號量 對象,
然而,在 wait 操作完成后,信號量的計數會減1,
當為0時,線程會阻塞
同樣地,只有當前擁有該mutex 的線程可以調用 ReleaseMutex 函數
但可以在任何線程通過調用 ReleaseSemaphore 函數來增加 信號量的計數

A thread can decrement a semaphore's count more than once by repeatedly specifying the same semaphore object in calls to any of the wait functions. However, calling one of the multiple-object wait functions with an array that contains multiple handles of the same semaphore does not result in multiple decrements.

線程可以通過反復等待一個信號量對象來讓信號量的計數自減
但是,如果調用 multiple-object wait 系列函數,等待的數組里指定為多個相同的信號量,這時并不會導致信號量的計數值多次自減。

相關WIN-API函數:
CreateSemaphore()
OpenSemaphore()
ReleaseSemaphore()
WaitForSingleObject()
CloseHandle()

本文內容摘自MSDN,有些地方翻譯得不好
歡迎交流,指正
聯系QQ:    859934020(經常隱身)
聯系E-mail:  kredraw@21cn.com

Feedback

# re: Windows多線程之信號量(Semaphore) {不斷補充中...最后更新08.08.26}[未登錄]  回復  更多評論   

2008-08-27 10:17 by 陳梓瀚(vczh)
這種玩意兒還有Mutex , WaitableTimer等等,可以用于進程間通訊。CriticalSection只能夠進程內部通訊。

# re: Windows多線程之信號量(Semaphore) {不斷補充中...最后更新08.08.26}  回復  更多評論   

2008-08-27 10:30 by free2000fly
"同樣地,只有創建 mutex 的線程可以調用 ReleaseMutex 函數 "
應為
"同樣地,只有當前擁有 mutex 的線程可以成功地調用 ReleaseMutex 函數 "
謝謝你的翻譯

# re: Windows多線程之信號量(Semaphore) {不斷補充中...最后更新08.08.27}  回復  更多評論   

2008-08-27 17:27 by 沒畫完的畫
@陳梓瀚(vczh)
嗯,有空一定補上去

# re: Windows多線程之信號量(Semaphore) {不斷補充中...最后更新08.08.27}  回復  更多評論   

2008-08-27 17:28 by 沒畫完的畫
@free2000fly
Thx
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            久久av一区二区三区漫画| 欧美一区免费| 性欧美1819sex性高清| 亚洲人成在线播放网站岛国| 久久亚洲精品伦理| 欧美二区视频| 日韩天堂在线观看| 亚洲欧洲av一区二区| 欧美一区二区三区四区夜夜大片| 欧美在线|欧美| 老司机免费视频久久| 欧美成人a视频| 国产精品大片wwwwww| 国产日产欧美一区| 亚洲黄色性网站| 香蕉成人久久| 免费视频一区| 一区二区三区四区国产| 欧美在线关看| 欧美日韩免费在线视频| 国产一区二区在线观看免费播放| 亚洲国产va精品久久久不卡综合| 一本色道久久综合| 久久精品一区| 亚洲精品免费电影| 久久国产精品亚洲77777| 欧美日韩视频第一区| 国产亚洲一级高清| 亚洲视频一起| 欧美mv日韩mv国产网站| 亚洲一区免费看| 免费高清在线视频一区·| 国产精品揄拍一区二区| 一本久道久久综合狠狠爱| 久久久噜噜噜久久中文字幕色伊伊| 91久久夜色精品国产网站| 久久国产欧美日韩精品| 欧美日韩综合视频| 亚洲人成人77777线观看| 久久久国产视频91| 亚洲一级黄色av| 欧美久久久久| 亚洲国产欧美不卡在线观看| 久久精品青青大伊人av| 亚洲午夜一区二区三区| 欧美人与性动交cc0o| 亚洲国产专区校园欧美| 欧美成人在线免费视频| 久久不射网站| 国产一区二区三区久久悠悠色av| 午夜精品久久久久久久男人的天堂| 亚洲国产精品v| 欧美不卡一卡二卡免费版| 在线日韩电影| 欧美不卡视频| 欧美福利在线| 99视频国产精品免费观看| 亚洲成人在线视频播放| 久久视频免费观看| 亚洲一区二区少妇| 国产精品视频成人| 亚洲男人第一av网站| 亚洲一区日本| 国产欧美日韩麻豆91| 久久gogo国模啪啪人体图| 亚洲欧美文学| 黄色亚洲大片免费在线观看| 免费的成人av| 欧美精品久久久久久| 亚洲视频香蕉人妖| 亚洲欧美视频在线| 激情久久五月天| 欧美刺激午夜性久久久久久久| 久久久久久久久久码影片| 亚洲第一视频网站| 亚洲乱码国产乱码精品精98午夜| 欧美精品粉嫩高潮一区二区 | 久久午夜电影网| 久久中文字幕导航| 日韩午夜电影av| 国产精品99久久久久久宅男| 国产裸体写真av一区二区| 久久久久综合| 欧美日韩另类国产亚洲欧美一级| 亚洲欧美成人一区二区在线电影| 欧美影视一区| 在线视频日本亚洲性| 午夜久久一区| 99国产精品久久久久久久成人热| 亚洲专区一区二区三区| 在线成人中文字幕| 日韩网站免费观看| ●精品国产综合乱码久久久久| 亚洲精品免费在线播放| 国产偷自视频区视频一区二区| 亚洲大片免费看| 国产精品羞羞答答xxdd| 亚洲国产精品成人精品| 国产精品一区视频网站| 亚洲国产精品va在线看黑人| 国产视频一区在线观看一区免费| 亚洲激情一区二区三区| 韩国亚洲精品| 亚洲视频axxx| 日韩一级大片在线| 久久一区中文字幕| 欧美一区二区三区视频在线 | 日韩一级在线| 在线成人激情| 午夜精品免费| 亚洲一区二区四区| 欧美.日韩.国产.一区.二区| 久久精品国产v日韩v亚洲| 国产精品qvod| 亚洲精品视频在线看| 亚洲国产精品久久久久婷婷老年 | 欧美激情视频一区二区三区在线播放| 国产欧美日韩精品在线| 亚洲精品视频免费在线观看| 影音先锋中文字幕一区| 亚洲女同精品视频| 亚洲欧美日韩区| 欧美日本高清| 亚洲国产一区视频| 亚洲欧洲日产国产网站| 久久在线免费观看视频| 久久综合伊人77777尤物| 国产日韩精品一区二区| 亚洲欧美在线磁力| 亚洲欧美成aⅴ人在线观看| 欧美日韩一区二区免费视频| 亚洲日本va午夜在线电影| 亚洲精品久久久久中文字幕欢迎你| 久久精品亚洲一区| 久热综合在线亚洲精品| 精品电影一区| 免费日韩av电影| 欧美激情精品久久久久久黑人| 亚洲人成7777| 欧美日韩视频在线一区二区| 亚洲日韩第九十九页| 亚洲图片欧美日产| 国产精品美女主播| 亚洲欧美中文字幕| 久久亚洲影院| 91久久精品一区二区三区| 欧美国产日韩一区二区在线观看| 亚洲韩国日本中文字幕| 亚洲视频在线观看网站| 国产日韩av一区二区| 久久亚洲国产精品日日av夜夜| 亚洲电影一级黄| 亚洲图片激情小说| 国产在线精品成人一区二区三区 | 国产精品日本欧美一区二区三区| 洋洋av久久久久久久一区| 亚洲女人小视频在线观看| 国产亚洲精久久久久久| 牛牛国产精品| 亚洲图片在线| 老司机午夜精品| 日韩视频免费在线| 国产精品亚洲综合久久| 久久综合电影| 一本久道久久综合狠狠爱| 欧美在线亚洲一区| 亚洲免费黄色| 国内免费精品永久在线视频| 欧美激情一区二区三区在线视频观看| 99一区二区| 免费成人你懂的| 午夜精品福利一区二区三区av| 永久域名在线精品| 欧美三级中文字幕在线观看| 欧美一区二区三区在线看| 亚洲精品国产精品国自产观看浪潮 | 激情综合色综合久久综合| 久久影院午夜片一区| 一区二区三区鲁丝不卡| 在线看视频不卡| 欧美午夜精品一区| 久久综合久色欧美综合狠狠 | 欧美日韩精品一区视频| 久久er99精品| 99精品欧美一区| 免费成人高清| 欧美亚洲日本国产| 99re6热在线精品视频播放速度| 国产日韩在线看片| 欧美天堂亚洲电影院在线播放| 欧美1区2区3区| 久久久伊人欧美| 欧美一级淫片播放口| 在线综合+亚洲+欧美中文字幕| 美女主播视频一区| 久久国产福利| 久久动漫亚洲| 欧美在线播放一区| 午夜一区二区三区不卡视频| 亚洲一区二区三|