Skip to content

Commit 3cc3ef3

Browse files
lechtenMax-Hailperin
authored andcommitted
Add defining conditions for deadlock (#120)
* Add 4 conditions for deadlock from [35] * Explain deadlock prevention in view of those conditions * Cite origin of conditions in notes
1 parent 01dce9c commit 3cc3ef3

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

synchronization.tex

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,9 +1529,27 @@ \subsection{The Deadlock Problem}\label{deadlock-problem-section}
15291529
deadlocked.
15301530

15311531
More generally, a \vocab{deadlock} exists whenever there is a cycle of
1532-
threads, each waiting for some resource held by the next. In the
1533-
example, there were two threads and the resources involved were two
1534-
mutexes. Although deadlocks can involve other resources as well
1532+
threads, each waiting for some resource held by the next, under the
1533+
following defining conditions:
1534+
\begin{enumerate}\label{deadlock-conditions}
1535+
\item Threads hold resources exclusively (``mutual exclusion'').
1536+
\item Threads hold some resources while waiting for additional ones
1537+
(``wait for'').
1538+
\item Resources cannot be removed from threads forcibly (``no
1539+
preemption'').
1540+
\item Threads wait in a circular chain such that each thread holds
1541+
resources that are requested by the next thread in the chain.
1542+
\end{enumerate}
1543+
1544+
In the example, there are two threads and the resources involved are
1545+
two mutexes. Clearly, mutexes are held exclusively (condition (1)),
1546+
each thread holds one mutex while waiting for another one (condition
1547+
(2)), mutexes are never removed by the operating system but threads
1548+
need to release them on their own (condition (3)), and both threads
1549+
wait for each other, forming the shortest circular chain possible
1550+
(condition (4)).
1551+
1552+
Although deadlocks can involve other resources as well
15351553
(consider readers/writers locks, for example), I will focus
15361554
on mutexes for simplicity.
15371555

@@ -1606,7 +1624,11 @@ \subsection{The Deadlock Problem}\label{deadlock-problem-section}
16061624
\subsection{Deadlock Prevention Through Resource Ordering}\label{deadlock-prevention-section}
16071625

16081626
The ideal way to cope with deadlocks is to prevent them from
1609-
happening. One very practical technique for deadlock prevention can
1627+
happening. In principle, deadlock prevention aims to ensure that at
1628+
least one of the four defining conditions is not satisfied.
1629+
One very practical technique for deadlock prevention targets the
1630+
circular wait situation characterized by condition (4) by imposing a
1631+
linear order in which resources need to be locked. This technique can
16101632
be illustrated through the example of transferring money between two bank accounts.
16111633
Each of the two accounts is stored somewhere in the computer's
16121634
memory, which can be specified through a numerical address. I will
@@ -2854,8 +2876,10 @@ \section*{Notes}
28542876
obtaining all necessary resources at the same time, rather than one by
28552877
one. Coffman\index{Coffman, E. G.@Coffman, E.~G.}, \index{Elphick,
28562878
M.}Elphick and \index{Shoshani, A.}Shoshani~\cite{max998} published a survey
2857-
of deadlock issues in 1971, which made the contemporary distinction
2858-
between deadlock prevention and deadlock avoidance.
2879+
of deadlock issues in 1971, which is the origin of the four defining
2880+
conditions of deadlocks presented on
2881+
page~\pageref{deadlock-conditions} and which made the
2882+
contemporary distinction between deadlock prevention and deadlock avoidance.
28592883

28602884
In 1971, \index{Courtois, P. J.@Courtois P.~J.}Courtois,
28612885
\index{Heymans, F.}Heymans, and \index{Parnas, D. L.@Parnas, D.~L.}Parnas~\cite{max997} described both

0 commit comments

Comments
 (0)