Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to model parallel threads in a UML sequence diagram

How can I model two parallel threads that perform operations on an object in a sequence diagram?

like image 945
Christian Avatar asked Sep 20 '17 09:09

Christian


People also ask

How do you show parallel process in sequence diagram?

The parallel combination fragment element should be used when creating a sequence diagram that shows parallel processing activities. The parallel combination fragment is drawn using a frame, and you place the text “par” in the frame's namebox.

How do you show multiple threads in a sequence diagram?

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.

How do you represent a thread in UML?

Activity, Sequence, and State Diagrams are all correct ways of showing thread behavior. 1st: (To vs's comments) There are two sets of diagrams or modeling elements in UML, static structure, as you put it, and behavioral.

How do you represent asynchronous call in sequence diagram?

Solid arrow heads represent synchronous calls, open arrow heads represent asynchronous messages, and dashed lines represent reply messages. If a caller sends a synchronous message, it must wait until the message is done, such as invoking a subroutine.


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.

![enter image description here

P.S: this example shows 2 threads, but you can add more threads by adding more horizontal dashed lines.

like image 74
Christophe Avatar answered Sep 19 '22 07:09

Christophe