<s>
A	O
seqlock	B-Application
(	O
short	O
for	O
sequence	O
lock	B-Operating_System
)	O
is	O
a	O
special	O
locking	B-Operating_System
mechanism	O
used	O
in	O
Linux	B-Application
for	O
supporting	O
fast	O
writes	O
of	O
shared	O
variables	O
between	O
two	O
parallel	O
operating	B-General_Concept
system	I-General_Concept
routines	O
.	O
</s>
<s>
The	O
seqlocks	B-Application
were	O
developed	O
by	O
Stephen	O
Hemminger	O
and	O
originally	O
called	O
frlocks	O
,	O
based	O
on	O
earlier	O
work	O
by	O
Andrea	O
Arcangeli	O
.	O
</s>
<s>
The	O
first	O
implementation	O
was	O
in	O
the	O
x86-64	O
time	O
code	O
where	O
it	O
was	O
needed	O
to	O
synchronize	O
with	O
user	O
space	O
where	O
it	O
was	O
not	O
possible	O
to	O
use	O
a	O
real	O
lock	B-Operating_System
.	O
</s>
<s>
It	O
is	O
a	O
reader	B-Operating_System
–	I-Operating_System
writer	I-Operating_System
consistent	O
mechanism	O
which	O
avoids	O
the	O
problem	O
of	O
writer	B-Operating_System
starvation	I-Operating_System
.	O
</s>
<s>
A	O
seqlock	B-Application
consists	O
of	O
storage	O
for	O
saving	O
a	O
sequence	O
number	O
in	O
addition	O
to	O
a	O
lock	B-Operating_System
.	O
</s>
<s>
The	O
lock	B-Operating_System
is	O
to	O
support	O
synchronization	O
between	O
two	O
writers	O
and	O
the	O
counter	O
is	O
for	O
indicating	O
consistency	O
in	O
readers	O
.	O
</s>
<s>
In	O
addition	O
to	O
updating	O
the	O
shared	O
data	O
,	O
the	O
writer	O
increments	O
the	O
sequence	O
number	O
,	O
both	O
after	O
acquiring	O
the	O
lock	B-Operating_System
and	O
before	O
releasing	O
the	O
lock	B-Operating_System
.	O
</s>
<s>
If	O
the	O
sequence	O
number	O
is	O
odd	O
on	O
either	O
occasion	O
,	O
a	O
writer	O
had	O
taken	O
the	O
lock	B-Operating_System
while	O
the	O
data	O
was	O
being	O
read	O
and	O
it	O
may	O
have	O
changed	O
.	O
</s>
<s>
The	O
reader	O
never	O
blocks	O
,	O
but	O
it	O
may	O
have	O
to	O
retry	O
if	O
a	O
write	O
is	O
in	O
progress	O
;	O
this	O
speeds	O
up	O
the	O
readers	O
in	O
the	O
case	O
where	O
the	O
data	O
was	O
not	O
modified	O
,	O
since	O
they	O
do	O
not	O
have	O
to	O
acquire	O
the	O
lock	B-Operating_System
as	O
they	O
would	O
with	O
a	O
traditional	O
read	O
–	O
write	O
lock	B-Operating_System
.	O
</s>
<s>
Also	O
,	O
writers	O
do	O
not	O
wait	O
for	O
readers	O
,	O
whereas	O
with	O
traditional	O
read	B-Operating_System
–	I-Operating_System
write	I-Operating_System
locks	I-Operating_System
they	O
do	O
,	O
leading	O
to	O
potential	O
resource	O
starvation	O
in	O
a	O
situation	O
where	O
there	O
are	O
a	O
number	O
of	O
readers	O
(	O
because	O
the	O
writer	O
must	O
wait	O
for	O
there	O
to	O
be	O
no	O
readers	O
)	O
.	O
</s>
<s>
Because	O
of	O
these	O
two	O
factors	O
,	O
seqlocks	B-Application
are	O
more	O
efficient	O
than	O
traditional	O
read	B-Operating_System
–	I-Operating_System
write	I-Operating_System
locks	I-Operating_System
for	O
the	O
situation	O
where	O
there	O
are	O
many	O
readers	O
and	O
few	O
writers	O
.	O
</s>
<s>
The	O
drawback	O
is	O
that	O
if	O
there	O
is	O
too	O
much	O
write	O
activity	O
or	O
the	O
reader	O
is	O
too	O
slow	O
,	O
they	O
might	O
livelock	B-Application
(	O
and	O
the	O
readers	O
may	O
starve	O
)	O
.	O
</s>
<s>
Updating	O
the	O
memory	O
block	O
being	O
pointed-to	O
is	O
fine	O
using	O
seqlocks	B-Application
,	O
but	O
updating	O
the	O
pointer	O
itself	O
is	O
not	O
allowed	O
.	O
</s>
<s>
In	O
a	O
case	O
where	O
the	O
pointers	O
themselves	O
must	O
be	O
updated	O
or	O
changed	O
,	O
using	O
read-copy-update	B-Operating_System
synchronization	O
is	O
preferred	O
.	O
</s>
<s>
Each	O
time	O
interrupt	O
updates	O
the	O
time	O
of	O
the	O
day	O
;	O
there	O
may	O
be	O
many	O
readers	O
of	O
the	O
time	O
for	O
operating	B-General_Concept
system	I-General_Concept
internal	O
use	O
and	O
applications	O
,	O
but	O
writes	O
are	O
relatively	O
infrequent	O
and	O
only	O
occur	O
one	O
at	O
a	O
time	O
.	O
</s>
<s>
One	O
subtle	O
issue	O
of	O
using	O
seqlocks	B-Application
for	O
a	O
time	O
counter	O
is	O
that	O
it	O
is	O
impossible	O
to	O
step	O
through	O
it	O
with	O
a	O
debugger	O
.	O
</s>
