网站大量收购独家精品文档,联系QQ:2885784924

Proactor和Reactor模式_继续并发系统设计的扫盲.doc

Proactor和Reactor模式_继续并发系统设计的扫盲.doc

  1. 1、本文档共5页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Proactor和Reactor模式_继续并发系统设计的扫盲

Proactor和Reactor模式_继续并发系统设计的扫盲 6.6.2008 Kevin Lynx Proactor和Reactor都是并发编程中的设计模式。在我看来,他们都是用于派发/分离IO操作事件的。这里所谓的 IO事件也就是诸如read/write的IO操作。派发/分离就是将单独的IO事件通知到上层模块。两个模式不同的地方 在于,Proactor用于异步IO,而Reactor用于同步IO。 摘抄一些关键的东西: Two patterns that involve event demultiplexors are called Reactor and Proactor [1]. The Reactor patterns involve synchronous I/O, whereas the Proactor pattern involves asynchronous I/O. 关于两个模式的大致模型,从以下文字基本可以明白: An example will help you understand the difference between Reactor and Proactor. We will focus on the read operation here, as the write implementation is similar. Heres a read in Reactor: * An event handler declares interest in I/O events that indicate readiness for read on a particular socket ; * The event demultiplexor waits for events ; * An event comes in and wakes-up the demultiplexor, and the demultiplexor calls the appropriate handler; * The event handler performs the actual read operation, handles the data read, declares renewed interest in ? I/O events, and returns control to the dispatcher . By comparison, here is a read operation in Proactor (true async): * A handler initiates an asynchronous read operation (note: the OS must support asynchronous I/O). In this ? case, the handler does not care about I/O readiness events, but is instead registers interest in receiving ? completion events; * The event demultiplexor waits until the operation is completed ; * While the event demultiplexor waits, the OS executes the read operation in a parallel kernel thread, puts ? data into a user-defined buffer, and notifies the event demultiplexor that the read is complete ; * The event demultiplexor calls the appropriate handler; * The event handler handles the data from user defined buffer, starts a new asynchronous operation, and returns ? control to the event demultiplexor. 可以看出,两个模式的相同点,都是对某个IO事件的事件通知(即告诉某个模块,这个IO操作可以进行或已经完成)。在结构 上,两者也有相同点:demultiplexor负责提交IO操作(异步)、查询设备是否可操作(同步),然后当条件满足时,就回调handler。 不同点在于,异步情况下(Proactor),当回调hand

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档