Reputation: 9763
I would like to be able to draw a nice concurrency diagram in my homework for a class I am taking. An ascii version would look something like the following. Is there any way to do this using latex that would make it look really nice and clean?
Thread A ----|=====read(7)=====|----------------------------------->
Thread B -------------|======write(-3)=====|-----|===read(-7)===|--->
Or at least something like this.
Upvotes: 4
Views: 731
Reputation: 4423
Yeah, this is an old question, but such diagram is still useful today.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
\begin{document}
\resizebox{\textwidth}{!}{%
\begin{tikzpicture}
\draw [line width=0.3mm] (0, 0) -- (16, 0);
\draw [line width=0.3mm] (0, -1) -- (16, -1);
\draw [line width=0.3mm] (0, -1 * 2) -- (16, -1 * 2);
\draw [line width=0.3mm] (0, -1 * 3) -- (16, -1 * 3);
\draw [line width=1mm, {Square}-{Square}, gray] (1, 0) -- (3, 0) node[midway,above] {Thread 1};
\draw [line width=1mm, {Square}-{Square}] (3, -1) -- (5, -1) node[midway,above] {Thread 2};
\draw [line width=1mm, {Square}-{Square}] (5, -1 * 2) -- (7, -1 * 2);
\draw [line width=1mm, {Square}-{Square}] (7, -1 * 3) -- (9, -1 * 3);
\end{tikzpicture}
}
\end{document}
Upvotes: 0
Reputation: 8724
The timing macros for PGF/TikZ look like they could be used to do what you want.
Upvotes: 0
Reputation: 19627
There are a quite a few drawing languages that integrate into tex.
As suggested in the comment, Dia, at least on linux, can dump to metapost code, which can be processed and inserted in your tex document.
You can also create a graphics file (jpg, png, pdf, eps) from your graphics program of choice, and just include that graphics file. This is probably the easiest route to go.
Off the top of my head, the drawing languages compatible with latex (non-exhaustive) are: PGF, TIKZ, MetaPost
TIKZ and PGF are pretty powerful, and you can check out a bunch of examples at texample.net
You could also use graphviz, and optionally dot2tex, which will translate your graphviz file into code latex can understand.
Upvotes: 1