如何用时序图来说明多线程?

发布于 2024-08-09 22:13:21 字数 174 浏览 5 评论 0原文

如何在序列图或类似图中清楚地说明多个执行线程?

我还没有找到任何明确的例子。我看到的所有图表都是用来说明单个线程的。


更新:接受的答案是我看到的最好的例子,但它确实还有一些不足之处。我最终在单独的序列图中说明了线程。我不确定序列图是否一定适用于多个线程。

How can you clearly illustrate multiple threads of execution in a sequence diagram or similar diagram?

I haven't been able to find any clear examples. All diagrams I see are used to illustrate a single thread.


Update: The accepted answer was the best example I saw but it does leave a fair bit to be desired. I ended up illustrating the threads in separate sequence diagrams. I'm not sure if the sequence diagram necessarily works for multiple threads.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

落日海湾 2024-08-16 22:13:21

这是一个可能有用的图表,在左侧您可以看到解释:
http://sdedit.sourceforge.net/multithreading/example/index.html

多线程时序图

Here is one diagram that may be useful, and on the left-hand side you can see the explanation:
http://sdedit.sourceforge.net/multithreading/example/index.html

Multithreading Sequence Diagram

浅沫记忆 2024-08-16 22:13:21

我在谷歌上发现了这个问题,并且不太喜欢已接受的答案,所以我只是想出了自己的答案。这就是我在应用程序中表示线程模型的方式(我的组织将其称为“并发观点”):

并发观点

希望它对某人有所帮助。

I found this question on Google and wasn't a huge fan of the accepted answer so I just came up with my own. This is how I represented the threading model in my application (my organization calls it the 'Concurrency Viewpoint'):

Concurrency viewpoint

Hopefully it helps someone.

桃气十足 2024-08-16 22:13:21

这是 sihaya 答案的重复,但详细介绍了如何使用网络上的工具来完成它,以及一个不会消失的视觉示例。

UML 序列图方法是使用“par”片段对并行处理的多个消息进行建模。下面是一个文本描述,当输入到网络上可用的 PlantUML 工具时,将生成下图。

@startuml

Person -> MicrowaveOven : Cook Food
activate MicrowaveOven
par
MicrowaveOven -> MicrowaveOven : Activate Magnetron
else
MicrowaveOven -> MicrowaveOven : Activate Rotation Motor
end

MicrowaveOven --> Person : Delicious Food
deactivate MicrowaveOven

@enduml

par UML 示例

This is a duplicate of sihaya's answer, but with details on how to accomplish it with tools on the web and a visual example that will not disappear.

The UML Sequence diagram approach is to use the "par" fragment to model multiple messages being processed in parallel. Below is a text description which when fed into the PlantUML tool available on the web will produce the diagram below.

@startuml

Person -> MicrowaveOven : Cook Food
activate MicrowaveOven
par
MicrowaveOven -> MicrowaveOven : Activate Magnetron
else
MicrowaveOven -> MicrowaveOven : Activate Rotation Motor
end

MicrowaveOven --> Person : Delicious Food
deactivate MicrowaveOven

@enduml

par UML example

云柯 2024-08-16 22:13:21

您可以使用“par”片段来模拟并行执行的多个同步调用。该片段由一个带有标签“par”的矩形组成。该矩形被分成多个框,每个框代表一个执行线程。

下面是从链接中提取的示例。

输入图片此处描述

本页给出了一个示例:
http://www.ibm.com/developerworks/rational/library/ 3101.html#N10227

You can use a "par" fragment to model multiple synchronous calls being executed in parallel. The fragment consists of a rectangle with the label "par". The rectangle is divided into multiple boxes, each representing a thread of execution.

Below an example extracted from the link.

enter image description here

An example is given on this page:
http://www.ibm.com/developerworks/rational/library/3101.html#N10227

ペ泪落弦音 2024-08-16 22:13:21

我喜欢@Brandon的回答。该图显示了清晰的线程通信模型。

我还发现了这份文档,其中有几种不同的方法 https://www .omg.org/ocup-2/documents/concurrency_in_uml_version_2.6.pdf

I like @Brandon's answer. That's a diagram that shows a clear threading communication model.

I also came across this document which has several different approaches https://www.omg.org/ocup-2/documents/concurrency_in_uml_version_2.6.pdf

再可℃爱ぅ一点好了 2024-08-16 22:13:21

您可能对消息序列图或MSC感兴趣。

这里是一张简要描述 MSC 的幻灯片。

You may be interested in Message Sequence Charts, or MSC.

Here is a slide describing MSC in a nutshell.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文