你的位置:pcMing工作室 >> 资讯 >> 编程开发 >> C++编程 >> 详细内容 在线投稿

Winsock 完成端口模型简介

排行榜 收藏 打印 发给朋友 举报 来源: 互联网   发布者:未知
热度1127票  浏览380次 【共0条评论】【我要评论 时间:2010年4月08日 19:56
pcMing工作室:x&BG$?6O3N)JH8c

E3E r2P;By:B0The most important property of a completion port is the concurrency value. The concurrency value of a completion port is specified when the completion port is created. This value limits the number of runnable threads associated with the completion port. When the total number of runnable threads associated with the completion port reaches the concurrency value, the system blocks the execution of any subsequent threads that specify the completion port until the number of runnable threads associated with the completion port drops below the concurrency value. The most efficient scenario occurs when there are completion packets waiting in the queue, but no waits can be satisfied because the port has reached its concurrency limit. In this case, when a running thread calls GetQueuedCompletionStatus, it will immediately pick up the queued completion packet. No context switches will occur, because the running thread is continually picking up completion packets and the other threads are unable to run. pcMing工作室 }lF(@8i"L Fr O

pcMing工作室 \;K|~+rd-f-d

完成端口最重要的特性就是并发量。完成端口的并发量可以在创建该完成端口时指定。该并发量限制了与该完成端口相关联的可运行线程的数目。当与该完成端口相关联的可运行线程的总数目达到了该并发量,系统就会阻塞任何与该完成端口相关联的后续线程的执行,直到与该完成端口相关联的可运行线程数目下降到小于该并发量为止。最有效的假想是发生在有完成包在队列中等待,而没有等待被满足,因为此时完成端口达到了其并发量的极限。此时,一个正在运行中的线程调用 GetQueuedCompletionStatus时,它就会立刻从队列中取走该完成包。这样就不存在着环境的切换,因为该处于运行中的线程就会连续不断地从队列中取走完成包,而其他的线程就不能运行了。

,C;RU] TX wizh0 pcMing工作室-v$r$z%]_

  

lO1x5XU)?0 pcMing工作室!M^:u'\$V2\5f

The best value to pick for the concurrency value is the number of CPUs on the machine. If your transaction required a lengthy computation, a larger concurrency value will allow more threads to run. Each transaction will take longer to complete, but more transactions will be processed at the same time. It is easy to experiment with the concurrency value to achieve the best effect for your application. pcMing工作室8J4~({0zM5z!r+T5Z

pcMing工作室M,g^3O$t]C

对于并发量最好的挑选值就是您计算机中cpu的数目。如果您的事务处理需要一个漫长的计算时间,一个比较大的并发量可以允许更多线程来运行。虽然完成每个事务处理需要花费更长的时间,但更多的事务可以同时被处理。对于应用程序来说,很容易通过测试并发量来获得最好的效果。

JM!~C]Z%^0 pcMing工作室 CT;G0B b&GT2U0L;LV:r

   pcMing工作室 u/qu"F2F(?WYh2dc

pcMing工作室f?N4T8x

The PostQueuedCompletionStatus function allows an application to queue its own special-purpose I/O completion packets to the completion port without starting an asynchronous I/O operation. This is useful for notifying worker threads of external events.

;G FI"_,j$J:Q)XkV0 pcMing工作室k+Vg_\B

PostQueuedCompletionStatus函数允许应用程序可以针对自定义的专用I/O完成包进行排队,而无需启动一个异步I/O操作。这点对于通知外部事件的工作者线程来说很有用。 pcMing工作室%x5|&\]H|n&t7R

*[;ne$`B/o5r0   pcMing工作室j3bz-g H `1z

pcMing工作室ENX)D#D

The completion port is freed when there are no more references to it. The completion port handle and every file handle associated with the completion port reference the completion port. All the handles must be closed to free the completion port. To close the port handle, call the CloseHandle function.

(fx1A:p'V&`0在没有更多的引用针对某个完成端口时,需要释放该完成端口。该完成端口句柄以及与该完成端口相关联的所有文件句柄都需要被释放。调用CloseHandle可以释放完成端口的句柄。
顶:52 踩:61
对本文中的事件或人物打分:
当前平均分:-0.28 (346次打分)
对本篇资讯内容的质量打分:
当前平均分:-0.42 (330次打分)
【已经有338人表态】
50票
感动
40票
路过
50票
高兴
35票
难过
31票
搞笑
41票
愤怒
48票
无聊
43票
同情
上一篇 下一篇
发表评论
换一张

网友评论仅供网友表达个人看法,并不表明本网同意其观点或证实其描述。

查看全部回复【已有0位网友发表了看法】

网络资源