Skip to content
Graphviz (DOT) templates

Petri Net — Mutex

Two processes competing for a shared resource via mutex token.

Template previewGraphviz (DOT)
pn Idle1 P1.idle ● Acq1 acquire1 Idle1->Acq1 CS1 P1.CS Rel1 release1 CS1->Rel1 Idle2 P2.idle ● Acq2 acquire2 Idle2->Acq2 CS2 P2.CS Rel2 release2 CS2->Rel2 Mut mutex ● Mut->Acq1 Mut->Acq2 Acq1->CS1 Rel1->Idle1 Rel1->Mut Acq2->CS2 Rel2->Idle2 Rel2->Mut

What this template contains

Graph
Directed
Edges
13
Source
22 lines

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;
}