Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to represent thread waiting for a signal on a Sequence Diagram?

A common multi-threaded implementation is to have some class where Method_A() is running in a thread and sits blocked waiting for some signal/event member variable (e.g. WaitForSingleObject).

Interacting classes running in different thread will then call Method_B() which does some work, sets the signal/event variable, perhaps does some more work, then returns.

How do I represent this interaction on a Sequence Diagram?

Should I have two lifelines, one for each thread, even though they are operating on the same instance of the class? My modelling tool (Enterprise Architect 12) doesn't allow the same class to appear twice on a Sequence Diagram, so seems to discourage this.


Edit: Geert has noted that the Sequence Diagram should use instances, not classes, which is a fair comment. However the problem is the same: multiple lifelines would imply multiple instances, but in the question Method_A() and Method_B() are operating on the same instance, just from different threads. How can that be represented?

like image 696
GrahamS Avatar asked Dec 24 '22 06:12

GrahamS


1 Answers

The approach I have decided to take is to add two lifelines for the same instance, then label one lifeline with the <<thread>> stereotype and add the thread it runs in to the name:

My attempt at multi-threaded Sequence Diagram

I realise this is probably not standard UML, but it seems to get across all the information I want to express in a clear manner, which is the most important thing, right?

Martin Fowler does mention a few times in his book that sometimes a non-normative diagram is actually clearer. So that's my excuse. :)

like image 172
GrahamS Avatar answered Jan 02 '23 09:01

GrahamS