8

The active object design pattern as I understand is tying up a (private/dedicated) thread life time with an object and making it work on independent data. From some of the documentation I read , the evolution of this kind of paradigm was because of two reasons , first , managing raw threads would be pain and second more threads contending for the shared resource doesn't scale well using mutex and locks. while I agree with the first reason , I do not fully comprehend the second . Making an object active just makes the object independent but the problems like contention for lock/mutex is still there (as we still have shared queue/buffer), the object just delegated the sharing responsibility onto the message queue. The only advantage of this design pattern as i see is the case where I had to perform long asynch task on the shared object (now that i am just passing message to a shared queue , the threads no longer have to block for long on mutex/locks but they still will blocka and contend for publishing messages/task). Other than this case could someone tell more scenarios where this kind of design pattern will have other advantages.

The second question I have is (I just started digging around design patterns) , what is the conceptual difference between , active object , reactor and proactor design pattern . How do you decide in which design pattern is more efficient and suits your requirements more. It would be really nice if someone can demonstrate certain examples showing how the three design patterns will behave and which one has comparative advantage/disadvantage in different scenarios.

I am kind of confused as I have used active object (which used shared thread-safe buffer) and boost::asio(Proactor) both to do similar kind of async stuff , I would like to know if any one has more insights on applicability of different patterns when approaching a problem.

4

1 回答 1

6

ACE 网站上有一些关于Active ObjectProactorReactor设计模式的非常好的论文。他们意图的简短摘要:

主动对象设计模式将方法执行与方法调用分离,以增强并发性并简化对驻留在其自己的控制线程中的对象的同步访问。也称为:并发对象、Actor。

Proactor模式支持多个事件处理程序的多路分解和分派,这些事件处理程序由异步事件的完成触发。这种模式在 Boost.Asio 中被大量使用。

Reactor设计模式处理由一个或多个客户端同时交付给应用程序的服务请求。应用程序中的每个服务可能包含多个方法,并由一个单独的事件处理程序表示,该事件处理程序负责调度特定于服务的请求。也称为:调度程序、通知程序。

于 2012-04-27T13:09:38.323 回答