<s>
Record	B-Operating_System
locking	I-Operating_System
is	O
the	O
technique	O
of	O
preventing	O
simultaneous	O
access	O
to	O
data	O
in	O
a	O
database	O
,	O
to	O
prevent	O
inconsistent	O
results	O
.	O
</s>
<s>
Clerks	O
1	O
and	O
2	O
both	O
retrieve	O
(	O
i.e.	O
,	O
copy	O
)	O
the	O
account	O
's	O
record	B-Application
.	O
</s>
<s>
Clerk	O
2	O
applies	O
a	O
different	O
transaction	O
to	O
his	O
saved	O
copy	O
,	O
and	O
saves	O
the	O
result	O
,	O
based	O
on	O
the	O
original	O
record	B-Application
and	O
his	O
changes	O
,	O
overwriting	O
the	O
transaction	O
entered	O
by	O
clerk	O
1	O
.	O
</s>
<s>
The	O
record	B-Application
no	O
longer	O
reflects	O
the	O
first	O
transaction	O
,	O
as	O
if	O
it	O
had	O
never	O
taken	O
place	O
.	O
</s>
<s>
A	O
simple	O
way	O
to	O
prevent	O
this	O
is	O
to	O
lock	B-Application
the	I-Application
file	I-Application
whenever	O
a	O
record	B-Application
is	O
being	O
modified	O
by	O
any	O
user	O
,	O
so	O
that	O
no	O
other	O
user	O
can	O
save	O
data	O
.	O
</s>
<s>
This	O
prevents	O
records	O
from	O
being	O
overwritten	O
incorrectly	O
,	O
but	O
allows	O
only	O
one	O
record	B-Application
to	O
be	O
processed	O
at	O
a	O
time	O
,	O
locking	O
out	O
other	O
users	O
who	O
need	O
to	O
edit	O
records	O
at	O
the	O
same	O
time	O
.	O
</s>
<s>
To	O
allow	O
several	O
users	O
to	O
edit	O
a	O
database	B-Application
table	I-Application
at	O
the	O
same	O
time	O
and	O
also	O
prevent	O
inconsistencies	O
created	O
by	O
unrestricted	O
access	O
,	O
a	O
single	O
record	B-Application
can	O
be	O
locked	O
when	O
retrieved	O
for	O
editing	O
or	O
updating	O
.	O
</s>
<s>
Anyone	O
attempting	O
to	O
retrieve	O
the	O
same	O
record	B-Application
for	O
editing	O
is	O
denied	O
write	O
access	O
because	O
of	O
the	O
lock	O
(	O
although	O
,	O
depending	O
on	O
the	O
implementation	O
,	O
they	O
may	O
be	O
able	O
to	O
view	O
the	O
record	B-Application
without	O
editing	O
it	O
)	O
.	O
</s>
<s>
Once	O
the	O
record	B-Application
is	O
saved	O
or	O
edits	O
are	O
canceled	O
,	O
the	O
lock	O
is	O
released	O
.	O
</s>
<s>
If	O
the	O
bank	O
clerks	O
(	O
to	O
follow	O
the	O
illustration	O
above	O
)	O
are	O
serving	O
two	O
customers	O
,	O
but	O
their	O
accounts	O
are	O
contained	O
in	O
one	O
ledger	O
,	O
then	O
the	O
entire	O
ledger	O
,	O
or	O
one	O
or	O
more	O
database	B-Application
tables	I-Application
,	O
would	O
need	O
to	O
be	O
made	O
available	O
for	O
editing	O
to	O
the	O
clerks	O
in	O
order	O
for	O
each	O
to	O
complete	O
a	O
transaction	O
,	O
one	O
at	O
a	O
time	O
(	O
file	B-Application
locking	I-Application
)	O
.	O
</s>
<s>
If	O
the	O
clerks	O
can	O
remove	O
one	O
page	O
from	O
the	O
ledger	O
,	O
containing	O
the	O
account	O
of	O
the	O
current	O
customer	O
(	O
plus	O
several	O
other	O
accounts	O
)	O
,	O
then	O
multiple	O
customers	O
can	O
be	O
serviced	O
concurrently	B-Operating_System
,	O
provided	O
that	O
each	O
customer	O
's	O
account	O
is	O
found	O
on	O
a	O
different	O
page	O
than	O
the	O
others	O
.	O
</s>
<s>
This	O
is	O
analogous	O
to	O
a	O
record	B-Application
level	O
lock	O
and	O
is	O
normally	O
the	O
highest	O
degree	O
of	O
locking	O
granularity	O
in	O
a	O
database	O
management	O
system	O
.	O
</s>
<s>
In	O
a	O
SQL	B-Language
database	I-Language
,	O
a	O
record	B-Application
is	O
typically	O
called	O
a	O
"	O
row	O
"	O
.	O
</s>
<s>
The	O
introduction	O
of	O
granular	O
(	O
subset	O
)	O
locks	O
creates	O
the	O
possibility	O
for	O
a	O
situation	O
called	O
deadlock	B-Operating_System
.	O
</s>
<s>
Deadlock	B-Operating_System
is	O
possible	O
when	O
incremental	O
locking	O
(	O
locking	O
one	O
entity	O
,	O
then	O
locking	O
one	O
or	O
more	O
additional	O
entities	O
)	O
is	O
used	O
.	O
</s>
<s>
Record	B-Application
locks	O
need	O
to	O
be	O
managed	O
between	O
the	O
entities	O
requesting	O
the	O
records	O
such	O
that	O
no	O
entity	O
is	O
given	O
too	O
much	O
service	O
via	O
successive	O
grants	O
,	O
and	O
no	O
other	O
entity	O
is	O
effectively	O
locked	O
out	O
.	O
</s>
<s>
Exclusive	O
locks	O
are	O
exclusively	O
held	O
by	O
a	O
single	O
entity	O
,	O
usually	O
for	O
the	O
purpose	O
of	O
writing	O
to	O
the	O
record	B-Application
.	O
</s>
<s>
not	O
hold	O
the	O
lock	O
across	O
system	O
or	O
function	O
calls	O
where	O
the	O
entity	O
is	O
no	O
longer	O
running	O
on	O
the	O
processor	O
–	O
this	O
can	O
lead	O
to	O
deadlock	B-Operating_System
;	O
</s>
<s>
waiters	O
)	O
can	O
be	O
held	O
in	O
a	O
list	O
that	O
is	O
serviced	O
in	O
a	O
round-robin	O
fashion	O
,	O
or	O
in	O
a	O
FIFO	B-Operating_System
queue	O
.	O
</s>
<s>
Shared	B-Operating_System
locks	I-Operating_System
differ	O
from	O
exclusive	O
locks	O
in	O
that	O
the	O
holder	O
list	O
can	O
contain	O
multiple	O
entries	O
.	O
</s>
<s>
Shared	B-Operating_System
locks	I-Operating_System
allow	O
all	O
holders	O
to	O
read	O
the	O
contents	O
of	O
the	O
record	B-Application
knowing	O
that	O
the	O
record	B-Application
cannot	O
be	O
changed	O
until	O
after	O
the	O
lock	O
has	O
been	O
released	O
by	O
all	O
holders	O
.	O
</s>
<s>
Exclusive	O
locks	O
cannot	O
be	O
obtained	O
when	O
a	O
record	B-Application
is	O
already	O
locked	O
(	O
exclusively	O
or	O
shared	O
)	O
by	O
another	O
entity	O
.	O
</s>
<s>
If	O
lock	O
requests	O
for	O
the	O
same	O
entity	O
are	O
queued	O
,	O
then	O
once	O
a	O
shared	B-Operating_System
lock	I-Operating_System
is	O
granted	O
,	O
any	O
queued	O
shared	B-Operating_System
locks	I-Operating_System
may	O
also	O
be	O
granted	O
.	O
</s>
<s>
If	O
an	O
exclusive	O
lock	O
is	O
found	O
next	O
on	O
the	O
queue	O
,	O
it	O
must	O
wait	O
until	O
all	O
shared	B-Operating_System
locks	I-Operating_System
have	O
been	O
released	O
.	O
</s>
<s>
As	O
with	O
exclusive	O
locks	O
,	O
these	O
shared	B-Operating_System
locks	I-Operating_System
should	O
be	O
held	O
for	O
the	O
least	O
time	O
possible	O
.	O
</s>
