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

沒畫完的畫

喂馬 劈柴 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>
            久久综合网色—综合色88| 久久亚洲精品网站| 亚洲日本中文字幕免费在线不卡| 在线观看一区视频| 在线中文字幕日韩| 欧美在线首页| 欧美激情精品久久久六区热门| 亚洲日产国产精品| 亚洲伦理中文字幕| 亚洲自拍三区| 亚洲第一天堂av| 中日韩美女免费视频网站在线观看| 亚洲婷婷免费| 欧美人与性动交α欧美精品济南到| 国产精品欧美久久| 国产精品福利影院| 亚洲精品1区| 久久久亚洲一区| 日韩天堂在线观看| 噜噜噜91成人网| 国产在线播放一区二区三区| 一本久久综合亚洲鲁鲁五月天| 免费欧美日韩| 性欧美长视频| 欧美天堂亚洲电影院在线播放| 亚洲成人资源网| 一区二区电影免费观看| 免费人成精品欧美精品| 国产一区二区三区丝袜| 香蕉av福利精品导航| 亚洲欧洲综合另类在线| 免费观看欧美在线视频的网站| 在线天堂一区av电影| 久久久人成影片一区二区三区| 国产农村妇女精品一区二区| 亚洲欧美日韩综合aⅴ视频| 亚洲精品小视频在线观看| 欧美老女人xx| 久久综合狠狠| 国产乱理伦片在线观看夜一区 | 久久久久久久综合| 亚洲尤物在线| 欧美国产成人在线| 99视频在线观看一区三区| 久久超碰97人人做人人爱| 国产亚洲成av人片在线观看桃| 欧美一级淫片aaaaaaa视频| 午夜精品久久久久久99热软件 | 国产精品久久久久9999高清| 女同性一区二区三区人了人一| 久久综合五月天婷婷伊人| 午夜精品美女自拍福到在线 | 亚洲午夜视频在线观看| 日韩视频一区二区三区在线播放| 久久精品日韩欧美| 亚洲国产合集| 一卡二卡3卡四卡高清精品视频| 亚洲黄色性网站| 久久综合久久美利坚合众国| 久热re这里精品视频在线6| 久久人人爽人人爽| 亚洲精品一区二区三区蜜桃久| 久久久久99精品国产片| 香蕉久久一区二区不卡无毒影院| 国产精品福利网| 亚洲香蕉在线观看| 小黄鸭精品密入口导航| 亚洲国产日韩欧美综合久久| 欧美亚州在线观看| 亚洲国产成人久久综合| 久久久777| 欧美77777| 亚洲精品日韩激情在线电影| 欧美第一黄色网| 久久精品人人做人人爽| 玖玖国产精品视频| 欧美69wwwcom| 99视频在线观看一区三区| 欧美日韩国产一区二区三区| 久久人人爽爽爽人久久久| 在线看国产日韩| 欧美国产成人在线| 日韩视频免费大全中文字幕| 欧美一级久久久| 激情丁香综合| 亚洲视频自拍偷拍| 久久久xxx| 欧美亚一区二区| 欧美一区二区女人| 亚洲综合国产激情另类一区| 国产精品自在在线| 鲁鲁狠狠狠7777一区二区| 亚洲国产精品福利| 午夜精品影院| 影音国产精品| 久久九九99视频| 最新日韩在线视频| 欧美在线视频二区| 亚洲人成精品久久久久| 久久婷婷国产综合国色天香| 亚洲三级网站| 久久久亚洲人| 亚洲影视中文字幕| 狠狠色狠狠色综合日日五| 香蕉久久国产| 亚洲国产美女精品久久久久∴| 亚洲免费一在线| 欧美体内she精视频| 久久久久久久久久久久久久一区| 亚洲乱码久久| 欧美高清在线一区| 一区在线观看| 国产精品入口夜色视频大尺度| 亚洲精品永久免费精品| 国产欧美日韩视频在线观看| 欧美大胆成人| 久久久99爱| 亚洲一区在线观看免费观看电影高清| 亚洲精品一区二区三区99| 国产欧美日韩视频一区二区三区| 欧美激情第五页| 久久亚洲春色中文字幕| 性久久久久久久久| 中文av一区特黄| 亚洲九九爱视频| 亚洲激情啪啪| 欧美风情在线| 欧美顶级艳妇交换群宴| 久久精品99| 午夜综合激情| 亚洲欧美中文日韩v在线观看| 亚洲免费黄色| 亚洲精品视频免费| 亚洲国内高清视频| 亚洲国产日韩欧美| 在线看无码的免费网站| 激情久久综合| 狠狠色狠狠色综合日日tαg| 国产一区二三区| 国产一区二区视频在线观看| 国产欧美日韩精品一区| 国产精品裸体一区二区三区| 国产精品对白刺激久久久| 欧美日韩在线三区| 欧美午夜精品久久久久久久| 欧美视频在线观看| 国产精品第三页| 国产精品一区毛片| 国产午夜精品美女毛片视频| 国产性天天综合网| 国产最新精品精品你懂的| 国产亚洲欧洲997久久综合| 国产视频在线一区二区 | 欧美激情久久久久久| 欧美国产91| 亚洲精品国产精品国产自| 亚洲精品中文字幕女同| 在线亚洲自拍| 欧美一区在线看| 一区二区三区高清在线| 亚洲在线免费| 久久久777| 欧美精品在线一区二区| 国产精品爱啪在线线免费观看 | 久久久久一本一区二区青青蜜月| 久久综合色8888| 欧美日本国产| 国产午夜精品美女视频明星a级| 一色屋精品视频在线看| 亚洲麻豆视频| 欧美亚洲一区二区在线| 久久手机免费观看| 亚洲国产另类精品专区 | 欧美成人在线免费视频| 日韩午夜在线电影| 性欧美videos另类喷潮| 欧美成人精品| 国产精品一区在线观看你懂的| 在线观看亚洲一区| 亚洲一区二区免费视频| 亚洲毛片在线观看| 欧美在线观看网址综合| 亚洲欧美怡红院| 欧美成人综合在线| 亚洲午夜电影| 欧美成人精品1314www| 国产欧美日韩不卡免费| 亚洲欧洲日本国产| 欧美一区日韩一区| 亚洲人午夜精品免费| 中文在线资源观看视频网站免费不卡| 国产精品蜜臀在线观看| 国产亚洲午夜| 亚洲桃色在线一区| 亚洲天堂成人| 欧美成人精品h版在线观看| 亚洲主播在线观看| 亚洲欧美国产不卡| 欧美精品免费在线| 欧美日本三级|