76

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.

Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
  • 1
    seems identical to http://stackoverflow.com/questions/954193/is-there-an-inituitive-uml-approach-to-depict-threads – feuGene Aug 06 '12 at 19:23

6 Answers6

48

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

pomber
  • 23,132
  • 10
  • 81
  • 94
James Black
  • 41,583
  • 10
  • 86
  • 166
  • 1
    I saw that. Not bad.. but does make me a little dizzy when I read it ;) – Marcus Leon Oct 29 '09 at 14:06
  • Handling multiple threads will be a bit daunting, as, part of the reason for using threads is that they are autonomous. You may want to do related threads together, as separate programs. So, Thread 1 (controller thread) starts, spawns 3 threads, they process and report back to controller. Then, these would be in one sequence diagram. There may be 20 other threads being ignored, but that is fine, as they are doing other unrelated tasks. – James Black Oct 29 '09 at 14:21
25

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.

Brandon
  • 4,491
  • 6
  • 38
  • 59
17

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

Reginald Blue
  • 930
  • 11
  • 26
10

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

JuanDM
  • 1,250
  • 10
  • 24
sihaya
  • 99
  • 1
  • 2
2

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

xaviersjs
  • 1,579
  • 1
  • 15
  • 25
-1

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

Here is a slide describing MSC in a nutshell.

mouviciel
  • 66,855
  • 13
  • 106
  • 140
  • Was there a link with examples of the charts? – Marcus Leon Oct 29 '09 at 14:07
  • 1
    I don't see how that represents multiple threads. I must need more caffeine. – Marcus Leon Oct 29 '09 at 14:25
  • This is a general formalism for representing activities running in parallel and communicating and synchronizing. This may be processes, threads, realtime tasks or even programs running on different computers. – mouviciel Oct 29 '09 at 15:13