<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
the	O
readers	B-Operating_System
–	I-Operating_System
writers	I-Operating_System
problems	I-Operating_System
are	O
examples	O
of	O
a	O
common	O
computing	O
problem	O
in	O
concurrency	B-Operating_System
.	O
</s>
<s>
There	O
are	O
at	O
least	O
three	O
variations	O
of	O
the	O
problems	O
,	O
which	O
deal	O
with	O
situations	O
in	O
which	O
many	O
concurrent	O
threads	B-Operating_System
of	O
execution	O
try	O
to	O
access	O
the	O
same	O
shared	O
resource	O
at	O
one	O
time	O
.	O
</s>
<s>
Some	O
threads	B-Operating_System
may	O
read	O
and	O
some	O
may	O
write	O
,	O
with	O
the	O
constraint	O
that	O
no	O
thread	B-Operating_System
may	O
access	O
the	O
shared	O
resource	O
for	O
either	O
reading	O
or	O
writing	O
while	O
another	O
thread	B-Operating_System
is	O
in	O
the	O
act	O
of	O
writing	O
to	O
it	O
.	O
</s>
<s>
(	O
In	O
particular	O
,	O
we	O
want	O
to	O
prevent	O
more	O
than	O
one	O
thread	B-Operating_System
modifying	O
the	O
shared	O
resource	O
simultaneously	O
and	O
allow	O
for	O
two	O
or	O
more	O
readers	O
to	O
access	O
the	O
shared	O
resource	O
at	O
the	O
same	O
time	O
)	O
.	O
</s>
<s>
A	O
readers	B-Operating_System
–	I-Operating_System
writer	I-Operating_System
lock	I-Operating_System
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
that	O
solves	O
one	O
or	O
more	O
of	O
the	O
readers	B-Operating_System
–	I-Operating_System
writers	I-Operating_System
problems	I-Operating_System
.	O
</s>
<s>
Suppose	O
we	O
have	O
a	O
shared	O
memory	O
area	O
(	O
critical	B-Operating_System
section	I-Operating_System
)	O
with	O
the	O
basic	O
constraints	O
detailed	O
above	O
.	O
</s>
<s>
It	O
is	O
possible	O
to	O
protect	O
the	O
shared	O
data	O
behind	O
a	O
mutual	O
exclusion	O
mutex	B-Operating_System
,	O
in	O
which	O
case	O
no	O
two	O
threads	B-Operating_System
can	O
access	O
the	O
data	O
at	O
the	O
same	O
time	O
.	O
</s>
<s>
This	O
is	O
the	O
motivation	O
for	O
the	O
first	O
readers	B-Operating_System
–	I-Operating_System
writers	I-Operating_System
problem	I-Operating_System
,	O
in	O
which	O
the	O
constraint	O
is	O
added	O
that	O
no	O
reader	O
shall	O
be	O
kept	O
waiting	O
if	O
the	O
share	O
is	O
currently	O
opened	O
for	O
reading	O
.	O
</s>
<s>
Before	O
entering	O
the	O
critical	B-Operating_System
section	I-Operating_System
,	O
every	O
new	O
reader	O
must	O
go	O
through	O
the	O
entry	O
section	O
.	O
</s>
<s>
This	O
is	O
done	O
to	O
avoid	O
race	B-Operating_System
conditions	I-Operating_System
on	O
the	O
readers	O
(	O
in	O
this	O
context	O
,	O
a	O
race	B-Operating_System
condition	I-Operating_System
is	O
a	O
condition	O
in	O
which	O
two	O
or	O
more	O
threads	B-Operating_System
are	O
waking	O
up	O
simultaneously	O
and	O
trying	O
to	O
enter	O
the	O
critical	B-Operating_System
section	I-Operating_System
;	O
without	O
further	O
constraint	O
,	O
the	O
behavior	O
is	O
nondeterministic	O
.	O
</s>
<s>
At	O
this	O
point	O
the	O
readers	O
are	O
not	O
locking	B-Operating_System
the	O
resource	O
.	O
</s>
<s>
They	O
are	O
only	O
locking	B-Operating_System
the	O
entry	O
section	O
so	O
no	O
other	O
reader	O
can	O
enter	O
it	O
while	O
they	O
are	O
in	O
it	O
.	O
</s>
<s>
Once	O
the	O
reader	O
is	O
done	O
executing	O
the	O
entry	O
section	O
,	O
it	O
will	O
unlock	O
it	O
by	O
signalling	O
the	O
mutex	B-Operating_System
.	O
</s>
<s>
Signalling	O
it	O
is	O
equivalent	O
to	O
:	O
mutex.V( )	O
in	O
the	O
above	O
code	O
.	O
</s>
<s>
This	O
means	O
that	O
a	O
stream	O
of	O
readers	O
can	O
subsequently	O
lock	O
all	O
potential	O
writers	O
out	O
and	O
starve	B-Operating_System
them	O
.	O
</s>
<s>
It	O
would	O
be	O
unfair	O
for	O
R2	O
to	O
jump	O
in	O
immediately	O
,	O
ahead	O
of	O
W	O
;	O
if	O
that	O
happened	O
often	O
enough	O
,	O
W	O
would	O
starve	B-Operating_System
.	O
</s>
<s>
This	O
is	O
the	O
motivation	O
for	O
the	O
second	O
readers	B-Operating_System
–	I-Operating_System
writers	I-Operating_System
problem	I-Operating_System
,	O
in	O
which	O
the	O
constraint	O
is	O
added	O
that	O
no	O
writer	O
,	O
once	O
added	O
to	O
the	O
queue	O
,	O
shall	O
be	O
kept	O
waiting	O
longer	O
than	O
absolutely	O
necessary	O
.	O
</s>
<s>
However	O
,	O
the	O
writer	O
will	O
not	O
be	O
able	O
to	O
access	O
the	O
resource	O
until	O
the	O
current	O
reader	O
has	O
released	O
the	O
resource	O
,	O
which	O
only	O
occurs	O
after	O
the	O
reader	O
is	O
finished	O
with	O
the	O
resource	O
in	O
the	O
critical	B-Operating_System
section	I-Operating_System
.	O
</s>
<s>
They	O
are	O
only	O
able	O
to	O
do	O
so	O
after	O
first	O
locking	B-Operating_System
the	O
readtry	O
semaphore	O
,	O
which	O
can	O
only	O
be	O
done	O
by	O
one	O
of	O
them	O
at	O
a	O
time	O
.	O
</s>
<s>
Their	O
sole	O
purpose	O
is	O
to	O
avoid	O
race	B-Operating_System
conditions	I-Operating_System
on	O
the	O
readers	O
and	O
writers	O
while	O
they	O
are	O
in	O
their	O
entry	O
or	O
exit	O
sections	O
.	O
</s>
<s>
In	O
fact	O
,	O
the	O
solutions	O
implied	O
by	O
both	O
problem	O
statements	O
can	O
result	O
in	O
starvation	B-Operating_System
the	O
first	O
one	O
may	O
starve	B-Operating_System
writers	O
in	O
the	O
queue	O
,	O
and	O
the	O
second	O
one	O
may	O
starve	B-Operating_System
readers	O
.	O
</s>
<s>
Therefore	O
,	O
the	O
third	O
readers	B-Operating_System
–	I-Operating_System
writers	I-Operating_System
problem	I-Operating_System
is	O
sometimes	O
proposed	O
,	O
which	O
adds	O
the	O
constraint	O
that	O
no	O
thread	B-Operating_System
shall	O
be	O
allowed	O
to	O
starve	B-Operating_System
;	O
that	O
is	O
,	O
the	O
operation	O
of	O
obtaining	O
a	O
lock	O
on	O
the	O
shared	O
data	O
will	O
always	O
terminate	O
in	O
a	O
bounded	O
amount	O
of	O
time	O
.	O
</s>
<s>
This	O
solution	O
can	O
only	O
satisfy	O
the	O
condition	O
that	O
"	O
no	O
thread	B-Operating_System
shall	O
be	O
allowed	O
to	O
starve	B-Operating_System
"	O
if	O
and	O
only	O
if	O
semaphores	O
preserve	O
first-in	O
first-out	O
ordering	O
when	O
blocking	O
and	O
releasing	O
threads	B-Operating_System
.	O
</s>
