Skip to content
Graphviz (DOT) templates

Petri Net — Mutex

Two processes competing for a shared resource via mutex token.

Template previewGraphviz (DOT)
Rendering…

Make it your own.

digraph pn {
  rankdir=LR;
  graph [bgcolor=transparent];
  node [fontname=Inter, fontsize=10];

  Idle1 [shape=circle, label="P1.idle\n●", style=filled, fillcolor="#dbeafe"];
  CS1 [shape=circle, label="P1.CS", style=filled, fillcolor="#dbeafe"];
  Idle2 [shape=circle, label="P2.idle\n●", style=filled, fillcolor="#dbeafe"];
  CS2 [shape=circle, label="P2.CS", style=filled, fillcolor="#dbeafe"];
  Mut [shape=circle, label="mutex\n●", style=filled, fillcolor="#fef3c7"];

  Acq1 [shape=rect, label="acquire1", style=filled, fillcolor="#dcfce7", height=0.4, width=0.2];
  Rel1 [shape=rect, label="release1", style=filled, fillcolor="#dcfce7", height=0.4, width=0.2];
  Acq2 [shape=rect, label="acquire2", style=filled, fillcolor="#dcfce7", height=0.4, width=0.2];
  Rel2 [shape=rect, label="release2", style=filled, fillcolor="#dcfce7", height=0.4, width=0.2];

  Idle1 -> Acq1 -> CS1;
  Mut -> Acq1; Acq1 -> Mut [style=invis];
  CS1 -> Rel1 -> Idle1;
  Rel1 -> Mut;

  Idle2 -> Acq2 -> CS2;
  Mut -> Acq2;
  CS2 -> Rel2 -> Idle2;
  Rel2 -> Mut;
}