How can I model two parallel threads that perform operations on an object in a sequence diagram?
-
2Two lifelines for the two threads. Consider using asynchronous calls on the target object – xmojmr Sep 20 '17 at 10:35
1 Answers
In a sequence diagram, a lifeline represents an individual participant in the interaction. So your object that is shared between the threads should appear once and only once in the diagram.
You would also represent with a lifeline each threaded object that interact with your shared object. It could be thread instantiations directly, or it could be several objects that are created in the context of the two threads.
But this is not sufficient. In principle, the sequence of the interactions with your object is indicated by the vertical order of the messages. So how to show that interactions may happen in parallel ?
For representing parallelism, you would use a combined fragment introduced by the operator par
. Graphically (see link), the combined fragment is represented as a boxed region in your sequence diagram, parallel sequences being separated by horizontal dashed lines (each of the slices would then correspond to one thread of execution.
P.S: this example shows 2 threads, but you can add more threads by adding more horizontal dashed lines.

- 68,716
- 7
- 72
- 138
-
Uhm, what are those 3 Generalization relations?? And why is the return to the the right followed by a sooo long execution? – qwerty_so Nov 16 '20 at 09:28
-
@qwerty_so indeed. A quick and dirty diagram made on the go with an online tool just to illustrater the `par`. Fortunately, I could find back the diagram and graphically edit it. Of course: plain arrow for synchronous message, dashed lines for return message. However on the right, these are not a very long activation after a return, but a creation messages, which looks like a return message despite it has completely different semantics. – Christophe Nov 16 '20 at 13:01
-
That return is a creation, of course. Now that the rest ist fine, this is clear as well :-) – qwerty_so Nov 16 '20 at 16:12