<s>
In	O
concurrent	B-Architecture
computing	I-Architecture
,	O
deadlock	B-Operating_System
is	O
any	O
situation	O
in	O
which	O
no	O
member	O
of	O
some	O
group	O
of	O
entities	O
can	O
proceed	O
because	O
each	O
waits	O
for	O
another	O
member	O
,	O
including	O
itself	O
,	O
to	O
take	O
action	O
,	O
such	O
as	O
sending	O
a	O
message	O
or	O
,	O
more	O
commonly	O
,	O
releasing	O
a	O
lock	B-Operating_System
.	O
</s>
<s>
Deadlocks	B-Operating_System
are	O
a	O
common	O
problem	O
in	O
multiprocessing	B-Operating_System
systems	O
,	O
parallel	B-Operating_System
computing	I-Operating_System
,	O
and	O
distributed	B-Architecture
systems	I-Architecture
,	O
because	O
in	O
these	O
contexts	O
systems	O
often	O
use	O
software	O
or	O
hardware	O
locks	O
to	O
arbitrate	O
shared	O
resources	O
and	O
implement	O
process	B-Operating_System
synchronization	O
.	O
</s>
<s>
In	O
an	O
operating	B-General_Concept
system	I-General_Concept
,	O
a	O
deadlock	B-Operating_System
occurs	O
when	O
a	O
process	B-Operating_System
or	O
thread	B-Operating_System
enters	O
a	O
waiting	O
state	B-Operating_System
because	O
a	O
requested	O
system	B-General_Concept
resource	I-General_Concept
is	O
held	O
by	O
another	O
waiting	O
process	B-Operating_System
,	O
which	O
in	O
turn	O
is	O
waiting	O
for	O
another	O
resource	O
held	O
by	O
another	O
waiting	O
process	B-Operating_System
.	O
</s>
<s>
If	O
a	O
process	B-Operating_System
remains	O
indefinitely	O
unable	O
to	O
change	O
its	O
state	B-Operating_System
because	O
resources	O
requested	O
by	O
it	O
are	O
being	O
used	O
by	O
another	O
process	B-Operating_System
that	O
itself	O
is	O
waiting	O
,	O
then	O
the	O
system	O
is	O
said	O
to	O
be	O
in	O
a	O
deadlock	B-Operating_System
.	O
</s>
<s>
In	O
a	O
communications	O
system	O
,	O
deadlocks	B-Operating_System
occur	O
mainly	O
due	O
to	O
loss	O
or	O
corruption	O
of	O
signals	O
rather	O
than	O
contention	O
for	O
resources	O
.	O
</s>
<s>
A	O
deadlock	B-Operating_System
situation	O
on	O
a	O
resource	O
can	O
arise	O
only	O
if	O
all	O
of	O
the	O
following	O
conditions	O
occur	O
simultaneously	O
in	O
a	O
system	O
:	O
</s>
<s>
Mutual	B-Operating_System
exclusion	I-Operating_System
:	O
At	O
least	O
one	O
resource	O
must	O
be	O
held	O
in	O
a	O
non-shareable	O
mode	O
;	O
that	O
is	O
,	O
only	O
one	O
process	B-Operating_System
at	O
a	O
time	O
can	O
use	O
the	O
resource	O
.	O
</s>
<s>
Otherwise	O
,	O
the	O
processes	B-Operating_System
would	O
not	O
be	O
prevented	O
from	O
using	O
the	O
resource	O
when	O
necessary	O
.	O
</s>
<s>
Only	O
one	O
process	B-Operating_System
can	O
use	O
the	O
resource	O
at	O
any	O
given	O
instant	O
of	O
time	O
.	O
</s>
<s>
Hold	O
and	O
wait	O
or	O
resource	O
holding	O
:	O
a	O
process	B-Operating_System
is	O
currently	O
holding	O
at	O
least	O
one	O
resource	O
and	O
requesting	O
additional	O
resources	O
which	O
are	O
being	O
held	O
by	O
other	O
processes	B-Operating_System
.	O
</s>
<s>
No	O
preemption	B-Operating_System
:	O
a	O
resource	O
can	O
be	O
released	O
only	O
voluntarily	O
by	O
the	O
process	B-Operating_System
holding	O
it	O
.	O
</s>
<s>
Circular	B-Operating_System
wait	I-Operating_System
:	O
each	O
process	B-Operating_System
must	O
be	O
waiting	O
for	O
a	O
resource	O
which	O
is	O
being	O
held	O
by	O
another	O
process	B-Operating_System
,	O
which	O
in	O
turn	O
is	O
waiting	O
for	O
the	O
first	O
process	B-Operating_System
to	O
release	O
the	O
resource	O
.	O
</s>
<s>
In	O
general	O
,	O
there	O
is	O
a	O
set	O
of	O
waiting	O
processes	B-Operating_System
,	O
P	O
=	O
{	O
P1	O
,	O
P2	O
,	O
…,	O
PN}	O
,	O
such	O
that	O
P1	O
is	O
waiting	O
for	O
a	O
resource	O
held	O
by	O
P2	O
,	O
P2	O
is	O
waiting	O
for	O
a	O
resource	O
held	O
by	O
P3	O
and	O
so	O
on	O
until	O
PN	O
is	O
waiting	O
for	O
a	O
resource	O
held	O
by	O
P1	O
.	O
</s>
<s>
While	O
these	O
conditions	O
are	O
sufficient	O
to	O
produce	O
a	O
deadlock	B-Operating_System
on	O
single-instance	O
resource	O
systems	O
,	O
they	O
only	O
indicate	O
the	O
possibility	O
of	O
deadlock	B-Operating_System
on	O
systems	O
having	O
multiple	O
instances	O
of	O
resources	O
.	O
</s>
<s>
Most	O
current	O
operating	B-General_Concept
systems	I-General_Concept
cannot	O
prevent	O
deadlocks	B-Operating_System
.	O
</s>
<s>
When	O
a	O
deadlock	B-Operating_System
occurs	O
,	O
different	O
operating	B-General_Concept
systems	I-General_Concept
respond	O
to	O
them	O
in	O
different	O
non-standard	O
manners	O
.	O
</s>
<s>
In	O
this	O
approach	O
,	O
it	O
is	O
assumed	O
that	O
a	O
deadlock	B-Operating_System
will	O
never	O
occur	O
.	O
</s>
<s>
This	O
is	O
also	O
an	O
application	O
of	O
the	O
Ostrich	B-Operating_System
algorithm	I-Operating_System
.	O
</s>
<s>
This	O
approach	O
was	O
initially	O
used	O
by	O
MINIX	B-Operating_System
and	O
UNIX	B-Application
.	O
</s>
<s>
This	O
is	O
used	O
when	O
the	O
time	O
intervals	O
between	O
occurrences	O
of	O
deadlocks	B-Operating_System
are	O
large	O
and	O
the	O
data	O
loss	O
incurred	O
each	O
time	O
is	O
tolerable	O
.	O
</s>
<s>
Ignoring	O
deadlocks	B-Operating_System
can	O
be	O
safely	O
done	O
if	O
deadlocks	B-Operating_System
are	O
formally	O
proven	O
to	O
never	O
occur	O
.	O
</s>
<s>
Under	O
the	O
deadlock	B-Operating_System
detection	O
,	O
deadlocks	B-Operating_System
are	O
allowed	O
to	O
occur	O
.	O
</s>
<s>
Then	O
the	O
state	B-Operating_System
of	O
the	O
system	O
is	O
examined	O
to	O
detect	O
that	O
a	O
deadlock	B-Operating_System
has	O
occurred	O
and	O
subsequently	O
it	O
is	O
corrected	O
.	O
</s>
<s>
An	O
algorithm	O
is	O
employed	O
that	O
tracks	O
resource	O
allocation	O
and	O
process	B-Operating_System
states	I-Operating_System
,	O
it	O
rolls	O
back	O
and	O
restarts	O
one	O
or	O
more	O
of	O
the	O
processes	B-Operating_System
in	O
order	O
to	O
remove	O
the	O
detected	O
deadlock	B-Operating_System
.	O
</s>
<s>
Detecting	O
a	O
deadlock	B-Operating_System
that	O
has	O
already	O
occurred	O
is	O
easily	O
possible	O
since	O
the	O
resources	O
that	O
each	O
process	B-Operating_System
has	O
locked	O
and/or	O
currently	O
requested	O
are	O
known	O
to	O
the	O
resource	O
scheduler	O
of	O
the	O
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
After	O
a	O
deadlock	B-Operating_System
is	O
detected	O
,	O
it	O
can	O
be	O
corrected	O
by	O
using	O
one	O
of	O
the	O
following	O
methods	O
:	O
</s>
<s>
Process	B-Operating_System
termination	O
:	O
one	O
or	O
more	O
processes	B-Operating_System
involved	O
in	O
the	O
deadlock	B-Operating_System
may	O
be	O
aborted	O
.	O
</s>
<s>
One	O
could	O
choose	O
to	O
abort	O
all	O
competing	O
processes	B-Operating_System
involved	O
in	O
the	O
deadlock	B-Operating_System
.	O
</s>
<s>
This	O
ensures	O
that	O
deadlock	B-Operating_System
is	O
resolved	O
with	O
certainty	O
and	O
speed	O
.	O
</s>
<s>
Or	O
,	O
one	O
could	O
choose	O
to	O
abort	O
one	O
process	B-Operating_System
at	O
a	O
time	O
until	O
the	O
deadlock	B-Operating_System
is	O
resolved	O
.	O
</s>
<s>
This	O
approach	O
has	O
a	O
high	O
overhead	O
because	O
after	O
each	O
abort	O
an	O
algorithm	O
must	O
determine	O
whether	O
the	O
system	O
is	O
still	O
in	O
deadlock	B-Operating_System
.	O
</s>
<s>
Several	O
factors	O
must	O
be	O
considered	O
while	O
choosing	O
a	O
candidate	O
for	O
termination	O
,	O
such	O
as	O
priority	O
and	O
age	O
of	O
the	O
process	B-Operating_System
.	O
</s>
<s>
Resource	O
preemption	B-Operating_System
:	O
resources	O
allocated	O
to	O
various	O
processes	B-Operating_System
may	O
be	O
successively	O
preempted	O
and	O
allocated	O
to	O
other	O
processes	B-Operating_System
until	O
the	O
deadlock	B-Operating_System
is	O
broken	O
.	O
</s>
<s>
Deadlock	B-Operating_System
prevention	O
works	O
by	O
preventing	O
one	O
of	O
the	O
four	O
Coffman	O
conditions	O
from	O
occurring	O
.	O
</s>
<s>
Removing	O
the	O
mutual	B-Operating_System
exclusion	I-Operating_System
condition	O
means	O
that	O
no	O
process	B-Operating_System
will	O
have	O
exclusive	O
access	O
to	O
a	O
resource	O
.	O
</s>
<s>
This	O
proves	O
impossible	O
for	O
resources	O
that	O
cannot	O
be	O
spooled	B-Device
.	O
</s>
<s>
But	O
even	O
with	O
spooled	B-Device
resources	O
,	O
the	O
deadlock	B-Operating_System
could	O
still	O
occur	O
.	O
</s>
<s>
Algorithms	O
that	O
avoid	O
mutual	B-Operating_System
exclusion	I-Operating_System
are	O
called	O
non-blocking	B-Operating_System
synchronization	I-Operating_System
algorithms	O
.	O
</s>
<s>
The	O
hold	O
and	O
wait	O
or	O
resource	O
holding	O
conditions	O
may	O
be	O
removed	O
by	O
requiring	O
processes	B-Operating_System
to	O
request	O
all	O
the	O
resources	O
they	O
will	O
need	O
before	O
starting	O
up	O
(	O
or	O
before	O
embarking	O
upon	O
a	O
particular	O
set	O
of	O
operations	O
)	O
.	O
</s>
<s>
Another	O
way	O
is	O
to	O
require	O
processes	B-Operating_System
to	O
request	O
resources	O
only	O
when	O
it	O
has	O
none	O
;	O
First	O
,	O
they	O
must	O
release	O
all	O
their	O
currently	O
held	O
resources	O
before	O
requesting	O
all	O
the	O
resources	O
they	O
will	O
need	O
from	O
scratch	O
.	O
</s>
<s>
Also	O
,	O
a	O
process	B-Operating_System
requiring	O
a	O
popular	O
resource	O
may	O
have	O
to	O
wait	O
indefinitely	O
,	O
as	O
such	O
a	O
resource	O
may	O
always	O
be	O
allocated	O
to	O
some	O
process	B-Operating_System
,	O
resulting	O
in	O
resource	B-Operating_System
starvation	I-Operating_System
.	O
</s>
<s>
(	O
These	O
algorithms	O
,	O
such	O
as	O
serializing	B-Operating_System
tokens	I-Operating_System
,	O
are	O
known	O
as	O
the	O
all-or-none	O
algorithms	O
.	O
)	O
</s>
<s>
The	O
no	O
preemption	B-Operating_System
condition	O
may	O
also	O
be	O
difficult	O
or	O
impossible	O
to	O
avoid	O
as	O
a	O
process	B-Operating_System
has	O
to	O
be	O
able	O
to	O
have	O
a	O
resource	O
for	O
a	O
certain	O
amount	O
of	O
time	O
,	O
or	O
the	O
processing	O
outcome	O
may	O
be	O
inconsistent	O
or	O
thrashing	B-General_Concept
may	O
occur	O
.	O
</s>
<s>
However	O
,	O
the	O
inability	O
to	O
enforce	O
preemption	B-Operating_System
may	O
interfere	O
with	O
a	O
priority	O
algorithm	O
.	O
</s>
<s>
Preemption	B-Operating_System
of	O
a	O
"	O
locked	O
out	O
"	O
resource	O
generally	O
implies	O
a	O
rollback	B-Application
,	O
and	O
is	O
to	O
be	O
avoided	O
since	O
it	O
is	O
very	O
costly	O
in	O
overhead	O
.	O
</s>
<s>
Algorithms	O
that	O
allow	O
preemption	B-Operating_System
include	O
lock-free	B-Operating_System
and	I-Operating_System
wait-free	I-Operating_System
algorithms	I-Operating_System
and	O
optimistic	B-Operating_System
concurrency	I-Operating_System
control	I-Operating_System
.	O
</s>
<s>
If	O
a	O
process	B-Operating_System
holding	O
some	O
resources	O
and	O
requests	O
for	O
some	O
another	O
resource(s )	O
that	O
cannot	O
be	O
immediately	O
allocated	O
to	O
it	O
,	O
the	O
condition	O
may	O
be	O
removed	O
by	O
releasing	O
all	O
the	O
currently	O
being	O
held	O
resources	O
of	O
that	O
process	B-Operating_System
.	O
</s>
<s>
The	O
final	O
condition	O
is	O
the	O
circular	B-Operating_System
wait	I-Operating_System
condition	O
.	O
</s>
<s>
Approaches	O
that	O
avoid	O
circular	B-Operating_System
waits	I-Operating_System
include	O
disabling	O
interrupts	O
during	O
critical	O
sections	O
and	O
using	O
a	O
hierarchy	O
to	O
determine	O
a	O
partial	O
ordering	O
of	O
resources	O
.	O
</s>
<s>
Similar	O
to	O
deadlock	B-Operating_System
prevention	O
,	O
deadlock	B-Operating_System
avoidance	O
approach	O
ensures	O
that	O
deadlock	B-Operating_System
will	O
not	O
occur	O
in	O
a	O
system	O
.	O
</s>
<s>
The	O
term	O
"	O
deadlock	B-Operating_System
avoidance	O
"	O
appears	O
to	O
be	O
very	O
close	O
to	O
"	O
deadlock	B-Operating_System
prevention	O
"	O
in	O
a	O
linguistic	O
context	O
,	O
but	O
they	O
are	O
very	O
much	O
different	O
in	O
the	O
context	O
of	O
deadlock	B-Operating_System
handling	O
.	O
</s>
<s>
Deadlock	B-Operating_System
avoidance	O
does	O
not	O
impose	O
any	O
conditions	O
as	O
seen	O
in	O
prevention	O
but	O
,	O
here	O
each	O
resource	O
request	O
is	O
carefully	O
analyzed	O
to	O
see	O
whether	O
it	O
could	O
be	O
safely	O
fulfilled	O
without	O
causing	O
deadlock	B-Operating_System
.	O
</s>
<s>
Deadlock	B-Operating_System
avoidance	O
requires	O
that	O
the	O
operating	B-General_Concept
system	I-General_Concept
be	O
given	O
in	O
advance	O
additional	O
information	O
concerning	O
which	O
resources	O
a	O
process	B-Operating_System
will	O
request	O
and	O
use	O
during	O
its	O
lifetime	O
.	O
</s>
<s>
Deadlock	B-Operating_System
avoidance	O
algorithm	O
analyzes	O
each	O
and	O
every	O
request	O
by	O
examining	O
that	O
there	O
is	O
no	O
possibility	O
of	O
deadlock	B-Operating_System
occurrence	O
in	O
the	O
future	O
if	O
the	O
requested	O
resource	O
is	O
allocated	O
.	O
</s>
<s>
One	O
of	O
the	O
most	O
used	O
deadlock	B-Operating_System
avoidance	O
algorithm	O
is	O
Banker	B-Operating_System
's	I-Operating_System
algorithm	I-Operating_System
.	O
</s>
<s>
A	O
livelock	O
is	O
similar	O
to	O
a	O
deadlock	B-Operating_System
,	O
except	O
that	O
the	O
states	O
of	O
the	O
processes	B-Operating_System
involved	O
in	O
the	O
livelock	O
constantly	O
change	O
with	O
regard	O
to	O
one	O
another	O
,	O
none	O
progressing	O
.	O
</s>
<s>
Livelock	O
is	O
a	O
special	O
case	O
of	O
resource	B-Operating_System
starvation	I-Operating_System
;	O
the	O
general	O
definition	O
only	O
states	O
that	O
a	O
specific	O
process	B-Operating_System
is	O
not	O
progressing	O
.	O
</s>
<s>
Livelock	O
is	O
a	O
risk	O
with	O
some	O
algorithms	O
that	O
detect	O
and	O
recover	O
from	O
deadlock	B-Operating_System
.	O
</s>
<s>
If	O
more	O
than	O
one	O
process	B-Operating_System
takes	O
action	O
,	O
the	O
deadlock	B-Operating_System
detection	O
algorithm	O
can	O
be	O
repeatedly	O
triggered	O
.	O
</s>
<s>
This	O
can	O
be	O
avoided	O
by	O
ensuring	O
that	O
only	O
one	O
process	B-Operating_System
(	O
chosen	O
arbitrarily	O
or	O
by	O
priority	O
)	O
takes	O
action	O
.	O
</s>
<s>
Distributed	O
deadlocks	B-Operating_System
can	O
occur	O
in	O
distributed	B-Architecture
systems	I-Architecture
when	O
distributed	B-General_Concept
transactions	I-General_Concept
or	O
concurrency	B-Operating_System
control	I-Operating_System
is	O
being	O
used	O
.	O
</s>
<s>
Distributed	O
deadlocks	B-Operating_System
can	O
be	O
detected	O
either	O
by	O
constructing	O
a	O
global	O
wait-for	B-Operating_System
graph	I-Operating_System
from	O
local	O
wait-for	B-Operating_System
graphs	I-Operating_System
at	O
a	O
deadlock	B-Operating_System
detector	O
or	O
by	O
a	O
distributed	B-Operating_System
algorithm	I-Operating_System
like	O
edge	O
chasing	O
.	O
</s>
<s>
Phantom	O
deadlocks	B-Operating_System
are	O
deadlocks	B-Operating_System
that	O
are	O
falsely	O
detected	O
in	O
a	O
distributed	B-Architecture
system	I-Architecture
due	O
to	O
system	O
internal	O
delays	O
but	O
do	O
not	O
actually	O
exist	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
a	O
process	B-Operating_System
releases	O
a	O
resource	O
R1	O
and	O
issues	O
a	O
request	O
for	O
R2	O
,	O
and	O
the	O
first	O
message	O
is	O
lost	O
or	O
delayed	O
,	O
a	O
coordinator	O
(	O
detector	O
of	O
deadlocks	B-Operating_System
)	O
could	O
falsely	O
conclude	O
a	O
deadlock	B-Operating_System
(	O
if	O
the	O
request	O
for	O
R2	O
while	O
having	O
R1	O
would	O
cause	O
a	O
deadlock	B-Operating_System
)	O
.	O
</s>
