# simple process synchronization diagram

I've drawn a few process synchronization diagrams in OpenOffice but I would like a more elegant solution than that.

What I'm trying to create is a process synchronization diagram like the one in the following picture. I've browsed texample.net, but couldn't find anything close to what I want to do.

Can somebody share his/her wisdom with me?

• Is there anything you have tried already? All I see are a few lines and arrows and a little bit of text. – Qrrbrbirlbel May 9 '13 at 18:24
• That's actually my OpenOffice drawing. I haven't been successful at all with TikZ, so I have no code. P1, P2 and P3 are supposed to be processes. The vertical axis represents the time. The arrows represent the packets exchanged by the processes. – gpo May 9 '13 at 18:27
• I guess what you are looking for is close to this TiKz example. – perror May 9 '13 at 18:58
• There are some decent tutorials in the first chapters of the TikZ manual, I think going through the first one or two of those should be enough to help you make that drawing. – Torbjørn T. May 9 '13 at 19:03
• Seems to me that you might want to try some of the TikZ tutorials, and read this: meta.tex.stackexchange.com/questions/3541/… – Andy Clifton May 9 '13 at 19:17

The calc library helps us to calculate the angle that is needed for the dashed line.

The points on the lines are pre-defined so that we simply can change the values there. As an example the coordinates p1-2 is relative to p1-1 as p1-3 to p1-2.

The p23 coordinate is the point where the solid lines transfers into the curved dashed line.

## Code

\documentclass[tikz,convert=false]{standalone} % the standalone class is for this MWE
% \usepackage{tikz}                       % use an appropriate class in your document
\usetikzlibrary{calc}
\tikzset{
bar/.style={
insert path={+(180:#1) edge[-,line cap=rect] +(right:#1) + (0,0)}
},
bar/.default=2pt+1.5\pgflinewidth,% mimics the | arrow
curved/.style={
out=200,
in=160,
distance=+1cm
}
}
\begin{document}
\begin{tikzpicture}[y=-1cm, x=1.5cm, >=stealth]
\foreach \xValue in {1,2,3}
\draw[|-] (\xValue,0) -- ++(90:4) node[at start, above] {P\xValue};

\path (1, .5) coordinate (p1-1)
++ (0,1  ) coordinate (p1-2)
++ (0, .5) coordinate (p1-3)
(2,1  ) coordinate (p2-1)
(2,1.4) coordinate (p2-2)
(2,2.5) coordinate (p2-3)
(2.7,1.8) coordinate (p23)
(3,2.7) coordinate (p3-1)
(3,3  ) coordinate (p3-2)
;

\foreach \cStart/\cTarget in {p1-1/p2-1, p1-1/p3-1, p2-2/p1-3}
\path [->] (\cStart) [bar] edge (\cTarget) (\cTarget) [bar];

\foreach \lBase/\cStart/\cTarget in {p1/1/2, p2/2/3}
\path [->] (\lBase-\cStart) [bar] edge[curved] (\lBase-\cTarget) (\lBase-\cTarget) [bar];

\path let \p1=(p2-2),
\p2=(p23),
\n1={atan2(\x2-\x1,\y2-\y1)}
in (\p1) edge (\p2)
(\p2) edge [out=\n1, in=\n1-180, dashed,->] (p3-2) (p3-2) [bar];

\draw[<-] (.5,4) -- ++ (270:1) node[above] {temps};
\end{tikzpicture}
\end{document}


## Output

• Feel free to ask for clarifications or other ways to declare certain points. – Qrrbrbirlbel May 9 '13 at 19:31
• I am very impressed... It is perfect! I can understand the code but it would have taken me a lot of time and effort to come up with it. Thanks a lot and I hope more people will find this helpful. – gpo May 9 '13 at 20:11