<s>
In	O
multithreaded	B-Operating_System
computing	B-General_Concept
,	O
the	O
ABA	B-Operating_System
problem	I-Operating_System
occurs	O
during	O
synchronization	O
,	O
when	O
a	O
location	O
is	O
read	O
twice	O
,	O
has	O
the	O
same	O
value	O
for	O
both	O
reads	O
,	O
and	O
the	O
read	O
value	O
being	O
the	O
same	O
twice	O
is	O
used	O
to	O
conclude	O
that	O
nothing	O
has	O
happened	O
in	O
the	O
interim	O
;	O
however	O
,	O
another	O
thread	B-Operating_System
can	O
execute	O
between	O
the	O
two	O
reads	O
and	O
change	O
the	O
value	O
,	O
do	O
other	O
work	O
,	O
then	O
change	O
the	O
value	O
back	O
,	O
thus	O
fooling	O
the	O
first	O
thread	B-Operating_System
into	O
thinking	O
nothing	O
has	O
changed	O
even	O
though	O
the	O
second	O
thread	B-Operating_System
did	O
work	O
that	O
violates	O
that	O
assumption	O
.	O
</s>
<s>
The	O
ABA	B-Operating_System
problem	I-Operating_System
occurs	O
when	O
multiple	O
threads	B-Operating_System
(	O
or	O
processes	B-Operating_System
)	O
accessing	O
shared	O
data	O
interleave	O
.	O
</s>
<s>
Below	O
is	O
a	O
sequence	O
of	O
events	O
that	O
illustrates	O
the	O
ABA	B-Operating_System
problem	I-Operating_System
:	O
</s>
<s>
is	O
preempted	B-Operating_System
,	O
allowing	O
process	O
to	O
run	O
,	O
</s>
<s>
is	O
preempted	B-Operating_System
,	O
allowing	O
process	O
to	O
run	O
,	O
</s>
<s>
A	O
common	O
case	O
of	O
the	O
ABA	B-Operating_System
problem	I-Operating_System
is	O
encountered	O
when	O
implementing	O
a	O
lock-free	B-Operating_System
data	O
structure	O
.	O
</s>
<s>
A	O
pointer	O
to	O
the	O
new	O
item	O
is	O
thus	O
often	O
equal	O
to	O
a	O
pointer	O
to	O
the	O
old	O
item	O
,	O
causing	O
an	O
ABA	B-Operating_System
problem	I-Operating_System
.	O
</s>
<s>
Consider	O
a	O
software	O
example	O
(	O
written	O
in	O
C++	O
)	O
of	O
ABA	O
using	O
a	O
lock-free	B-Operating_System
stack	B-Application
:	O
</s>
<s>
This	O
code	O
can	O
normally	O
prevent	O
problems	O
from	O
concurrent	O
access	O
,	O
but	O
suffers	O
from	O
ABA	B-Operating_System
problems	I-Operating_System
.	O
</s>
<s>
Thread	B-Operating_System
1	O
starts	O
running	O
pop	O
:	O
</s>
<s>
Thread	B-Operating_System
1	O
gets	O
interrupted	O
just	O
before	O
the	O
compare_exchange_weak	O
...	O
</s>
<s>
When	O
Thread	B-Operating_System
1	O
resumes	O
:	O
</s>
<s>
As	O
B	O
has	O
been	O
deleted	O
the	O
program	O
will	O
access	O
freed	O
memory	O
when	O
it	O
tries	O
to	O
look	O
at	O
the	O
first	O
element	O
on	O
the	O
stack	B-Application
.	O
</s>
<s>
In	O
C++	O
,	O
as	O
shown	O
here	O
,	O
accessing	O
freed	O
memory	O
is	O
undefined	B-Language
behavior	I-Language
:	O
this	O
may	O
result	O
in	O
crashes	O
,	O
data	O
corruption	O
or	O
even	O
just	O
silently	O
appear	O
to	O
work	O
correctly	O
.	O
</s>
<s>
For	O
example	O
,	O
an	O
algorithm	O
using	O
compare	B-Operating_System
and	I-Operating_System
swap	I-Operating_System
on	O
a	O
pointer	O
might	O
use	O
the	O
low	O
bits	O
of	O
the	O
address	O
to	O
indicate	O
how	O
many	O
times	O
the	O
pointer	O
has	O
been	O
successfully	O
modified	O
.	O
</s>
<s>
Because	O
of	O
this	O
,	O
the	O
next	O
compare-and-swap	B-Operating_System
will	O
fail	O
,	O
even	O
if	O
the	O
addresses	O
are	O
the	O
same	O
,	O
because	O
the	O
tag	O
bits	O
will	O
not	O
match	O
.	O
</s>
<s>
Such	O
tagged	O
state	O
references	O
are	O
also	O
used	O
in	O
transactional	B-Operating_System
memory	I-Operating_System
.	O
</s>
<s>
One	O
way	O
to	O
defer	O
reclamation	O
is	O
to	O
run	O
the	O
algorithm	O
in	O
an	O
environment	O
featuring	O
an	O
automatic	B-General_Concept
garbage	I-General_Concept
collector	I-General_Concept
;	O
a	O
problem	O
here	O
however	O
is	O
that	O
if	O
the	O
GC	O
is	O
not	O
lock-free	B-Operating_System
,	O
then	O
the	O
overall	O
system	O
is	O
not	O
lock-free	B-Operating_System
,	O
even	O
though	O
the	O
data	O
structure	O
itself	O
is	O
.	O
</s>
<s>
Hazard	O
pointers	O
are	O
lock-free	B-Operating_System
,	O
but	O
can	O
only	O
track	O
at	O
most	O
a	O
fixed	O
number	O
of	O
elements	O
per	O
thread	B-Operating_System
as	O
being	O
in-use	O
.	O
</s>
<s>
RCU	O
is	O
lock-free	B-Operating_System
,	O
but	O
is	O
n't	O
suitable	O
for	O
all	O
workloads	O
.	O
</s>
<s>
Rather	O
than	O
using	O
a	O
single	O
pointer-wide	O
compare-and-swap	B-Operating_System
instructions	O
,	O
</s>
<s>
intended	O
to	O
be	O
more	O
resistant	O
or	O
immune	O
to	O
the	O
ABA	B-Operating_System
problem	I-Operating_System
.	O
</s>
<s>
Some	O
architectures	O
provide	O
"	O
larger	O
"	O
atomic	O
operations	O
such	O
that	O
,	O
as	O
example	O
,	O
both	O
forward	O
and	O
backward	O
links	O
in	O
a	O
doubly	O
linked	O
list	O
can	O
be	O
updated	O
atomically	O
;	O
while	O
this	O
feature	O
is	O
architecture-dependent	O
,	O
it	O
,	O
in	O
particular	O
,	O
is	O
available	O
for	O
x86/x64	O
architectures	O
(	O
x86	O
allows	O
for	O
64-bit	O
CAS	O
,	O
and	O
all	O
modern	O
x64	O
CPUs	O
allow	O
for	O
128-bit	O
CAS	O
)	O
and	O
IBM	O
's	O
z/Architecture	B-Device
(	O
which	O
allows	O
for	O
up	O
to	O
128-bit	O
CAS	O
)	O
.	O
</s>
<s>
Some	O
architectures	O
provide	O
a	O
load	B-Operating_System
linked	I-Operating_System
,	I-Operating_System
store	I-Operating_System
conditional	I-Operating_System
instruction	O
in	O
which	O
the	O
store	O
is	O
performed	O
only	O
when	O
there	O
are	O
no	O
other	O
stores	O
of	O
the	O
indicated	O
location	O
.	O
</s>
<s>
Examples	O
include	O
DEC	B-Device
Alpha	I-Device
,	O
MIPS	B-Device
,	O
PowerPC	B-Architecture
,	O
RISC-V	B-Device
and	O
ARM	B-Architecture
(	O
v6	O
and	O
later	O
)	O
.	O
</s>
<s>
Since	O
these	O
instructions	O
provide	O
atomicity	O
using	O
the	O
address	O
rather	O
than	O
the	O
value	O
,	O
routines	O
using	O
these	O
instructions	O
are	O
immune	O
to	O
the	O
ABA	B-Operating_System
problem	I-Operating_System
.	O
</s>
