multithreading 如何在时序图中说明多线程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1643733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to illustrate multiple threads in sequence diagram?
提问by Marcus Leon
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.
更新:接受的答案是我看到的最好的例子,但它确实有一些不足之处。我最终在单独的序列图中说明了线程。我不确定序列图是否一定适用于多个线程。
采纳答案by James Black
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
这是一个可能有用的图表,在左侧你可以看到解释:http: //sdedit.sourceforge.net/multithreading/example/index.html
回答by Brandon
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'):
我在谷歌上发现了这个问题,并不是公认的答案的忠实粉丝,所以我只是想出了我自己的答案。这就是我在应用程序中表示线程模型的方式(我的组织将其称为“并发观点”):
Hopefully it helps someone.
希望它可以帮助某人。
回答by Reginald Blue
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.
这是 sihaya 答案的副本,但详细介绍了如何使用网络上的工具和一个不会消失的视觉示例来完成它。
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 PlantUMLtool available on the web will produce the diagram below.
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
回答by sihaya
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.
您可以使用“par”片段来模拟并行执行的多个同步调用。该片段由带有标签“par”的矩形组成。矩形被分成多个框,每个框代表一个执行线程。
Below an example extracted from the link.
下面是从链接中提取的示例。
An example is given on this page: http://www.ibm.com/developerworks/rational/library/3101.html#N10227
此页面上给出了一个示例:http: //www.ibm.com/developerworks/rational/library/3101.html#N10227
回答by xaviersjs
I like @Brandon's answer. That's a diagram that shows a clear threading communication model.
我喜欢@Brandon 的回答。这是一个显示清晰线程通信模型的图表。
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
我也遇到过这个文档,它有几种不同的方法https://www.omg.org/ocup-2/documents/concurrency_in_uml_version_2.6.pdf
回答by mouviciel
You may be interested in Message Sequence Charts, or MSC.
您可能对Message Sequence Charts或 MSC感兴趣。
Hereis a slide describing MSC in a nutshell.
这是一张简要描述 MSC 的幻灯片。