需要为多线程应用程序选择设计模式的建议 [英] Advice needed to choose design patterns for a multithreaded application

查看:126
本文介绍了需要为多线程应用程序选择设计模式的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多线程应用程序。它有四个线程,三个工作线程用于处理三个阶段的连续数据和一个UI线程用于显示。它是实时或接近实时的应用程序,以处理来自各种传感器的数据。它目前使用MFC的UI,但我认为这并不重要,因为我在谈论设计。



我正在寻找一个正确的架构或设计模式为这个应用程序。我阅读了面向模式的软件架构:并发和网络对象模式(POSA2) 及其来自作者网站的示例代码。



但是我仍然无法决定哪个设计模式适合应用程序, / p>


  • 领导者/追随者

  • 半同步/半同步

  • 反应器

  • Proactor

  • 活动对象



<

除了POSA2之外,我认为你可能会发现这些有用的:

$

b
$ b

并行编程的模式语言
http: //www.cise.ufl.edu/research/ParallelPatterns/



也推荐相关书籍:
Patterns for Parallel Programmingby平行模式资源


uiuc.edu/homes/snir/PPP/rel =nofollow> http://www.cs.uiuc.edu/homes/snir/PPP/



假设您在Windows上使用C ++,您应该真正了解PPL:



使用Microsoft Visual C ++的并行编程
分解的设计模式和多核架构协调
Colin Campbell,Ade Miller
http://parallelpatternscpp.codeplex.com/



您可以通过MSDN阅读整本书(免费):
http://msdn.microsoft.com/en-us/library/gg675934.aspx



特别是,看看选择正确的模式部分:
http://msdn.microsoft.com/en-us/library/gg663528.aspx



通过快速比较您的要求和在本节中,我认为管道模式(第7章)可能是一个很好的匹配:



管道出现在许多应用程序中。您可以在从实时事件流接收数据元素时使用流水线,例如股票行情带,用户生成的鼠标点击事件或通过网络到达的数据包的值。您还可以使用管道处理数据流中的元素,如同对压缩和加密一样,或者对视频帧流应用变换操作。在所有这些情况下,重要的是数据元素按顺序处理。您不能对这些情况使用并行循环,因为并行循环不会保留处理顺序。



更多: http://msdn.microsoft.com/en-us/library/gg663538.aspx


I have a multithreaded application. It has four threads, three worker threads for processing continuous data in three phase and one UI thread for display. It's real-time or near real-time application to process data coming from various sensors. It's currently using MFC for UI but I think it does not matter much since I am talking about design.

I am looking for a right architecture or design patterns for this application. I've read Pattern-Oriented Software Architecture: Patterns for Concurrent and Networked Objects (POSA2) and its example code from the author's web site.

But still I can't decide which design pattern(s) would be appropriate for the app among

  • Leader/Follower
  • Half-Sync/Half-Async
  • Reactor
  • Proactor
  • Active object

Can anyone give hint or advice?

解决方案

Beyond POSA2, I think you may find these helpful:

A Pattern Language for Parallel Programming http://www.cise.ufl.edu/research/ParallelPatterns/

Also recommend the related book: "Patterns for Parallel Programming" by Timothy G. Mattson, Beverly A. Sanders, Berna L. Massingill

Resources on Parallel Patterns http://www.cs.uiuc.edu/homes/snir/PPP/

Given that you're using C++ on Windows, you should really look into PPL:

Parallel Programming with Microsoft Visual C++ Design Patterns for Decomposition and Coordination on Multicore Architectures Colin Campbell, Ade Miller http://parallelpatternscpp.codeplex.com/

You can read the entire book (freely) via MSDN: http://msdn.microsoft.com/en-us/library/gg675934.aspx

In particular, take a look at "Selecting the Right Pattern" section here: http://msdn.microsoft.com/en-us/library/gg663528.aspx

By quickly comparing your requirements and the advice in this section, I think the Pipeline pattern (Chapter 7) might be a good match:

"Pipelines occur in many applications. You can use a pipeline when data elements are received from a real-time event stream, such as values on stock ticker tapes, user-generated mouse click events, or packets that arrive over the network. You can also use pipelines to process elements from a data stream, as is done with compression and encryption, or to apply transformation operations to streams of video frames. In all of these cases, it's important that the data elements are processed in sequential order. You can’t use a parallel loop for these cases because a parallel loop doesn't preserve the processing order."

More: http://msdn.microsoft.com/en-us/library/gg663538.aspx

这篇关于需要为多线程应用程序选择设计模式的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆