<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
load-linked/store	B-Operating_System
-conditional	I-Operating_System
(	O
LL/SC	B-Operating_System
)	O
,	O
sometimes	O
known	O
as	O
load-reserved/store	O
-conditional	O
(	O
LR/SC	B-Operating_System
)	O
,	O
are	O
a	O
pair	O
of	O
instructions	O
used	O
in	O
multithreading	O
to	O
achieve	O
synchronization	O
.	O
</s>
<s>
Load-link	O
returns	O
the	O
current	O
value	O
of	O
a	O
memory	B-General_Concept
location	I-General_Concept
,	O
while	O
a	O
subsequent	O
store-conditional	O
to	O
the	O
same	O
memory	B-General_Concept
location	I-General_Concept
will	O
store	O
a	O
new	O
value	O
only	O
if	O
no	O
updates	O
have	O
occurred	O
to	O
that	O
location	O
since	O
the	O
load-link	O
.	O
</s>
<s>
Together	O
,	O
this	O
implements	O
a	O
lock-free	B-Operating_System
,	O
atomic	B-General_Concept
,	O
read-modify-write	B-Operating_System
operation	O
.	O
</s>
<s>
LL/SC	B-Operating_System
was	O
originally	O
proposed	O
by	O
Jensen	O
,	O
Hagensen	O
,	O
and	O
Broughton	O
for	O
the	O
S-1	O
AAP	O
multiprocessor	O
at	O
Lawrence	O
Livermore	O
National	O
Laboratory	O
.	O
</s>
<s>
As	O
such	O
,	O
an	O
LL/SC	B-Operating_System
pair	O
is	O
stronger	O
than	O
a	O
read	O
followed	O
by	O
a	O
compare-and-swap	B-Operating_System
(	O
CAS	O
)	O
,	O
which	O
will	O
not	O
detect	O
updates	O
if	O
the	O
old	O
value	O
has	O
been	O
restored	O
(	O
see	O
ABA	B-Operating_System
problem	I-Operating_System
)	O
.	O
</s>
<s>
Real	O
implementations	O
of	O
LL/SC	B-Operating_System
do	O
not	O
always	O
succeed	O
even	O
if	O
there	O
are	O
no	O
concurrent	O
updates	O
to	O
the	O
memory	B-General_Concept
location	I-General_Concept
in	O
question	O
.	O
</s>
<s>
Any	O
exceptional	O
events	O
between	O
the	O
two	O
operations	O
,	O
such	O
as	O
a	O
context	B-Operating_System
switch	I-Operating_System
,	O
another	O
load-link	O
,	O
or	O
even	O
(	O
on	O
many	O
platforms	O
)	O
another	O
load	O
or	O
store	O
operation	O
,	O
will	O
cause	O
the	O
store-conditional	O
to	O
spuriously	O
fail	O
.	O
</s>
<s>
This	O
is	O
called	O
weak	O
LL/SC	B-Operating_System
by	O
researchers	O
,	O
as	O
it	O
breaks	O
many	O
theoretical	O
LL/SC	B-Operating_System
algorithms	O
.	O
</s>
<s>
LL/SC	B-Operating_System
is	O
more	O
difficult	O
to	O
emulate	O
than	O
CAS	O
.	O
</s>
<s>
Additionally	O
,	O
stopping	O
running	O
code	O
between	O
paired	O
LL/SC	B-Operating_System
instructions	O
,	O
such	O
as	O
when	O
single-stepping	O
through	O
code	O
,	O
can	O
prevent	O
forward	O
progress	O
,	O
making	O
debugging	O
tricky	O
.	O
</s>
<s>
Nevertheless	O
,	O
LL/SC	B-Operating_System
is	O
equivalent	O
to	O
CAS	O
in	O
the	O
sense	O
that	O
either	O
primitive	O
can	O
be	O
implemented	O
in	O
terms	O
of	O
the	O
other	O
,	O
in	O
O(1 )	O
and	O
in	O
a	O
wait-free	B-Operating_System
manner	O
.	O
</s>
<s>
LL/SC	B-Operating_System
instructions	O
are	O
supported	O
by	O
:	O
</s>
<s>
Typically	O
,	O
CPUs	O
track	O
the	O
load-linked	O
address	O
at	O
a	O
cache-line	B-General_Concept
or	O
other	O
granularity	O
,	O
such	O
that	O
any	O
modification	O
to	O
any	O
portion	O
of	O
the	O
cache	B-General_Concept
line	I-General_Concept
(	O
whether	O
via	O
another	O
core	O
's	O
store-conditional	O
or	O
merely	O
by	O
an	O
ordinary	O
store	O
)	O
is	O
sufficient	O
to	O
cause	O
the	O
store-conditional	O
to	O
fail	O
.	O
</s>
<s>
All	O
of	O
these	O
platforms	O
provide	O
weak	O
LL/SC	B-Operating_System
.	O
</s>
<s>
The	O
PowerPC	B-Architecture
implementation	O
allows	O
an	O
LL/SC	B-Operating_System
pair	O
to	O
wrap	O
loads	O
and	O
even	O
stores	O
to	O
other	O
cache	B-General_Concept
lines	I-General_Concept
(	O
although	O
this	O
approach	O
is	O
vulnerable	O
to	O
false	O
cache	B-General_Concept
line	I-General_Concept
sharing	O
)	O
.	O
</s>
<s>
This	O
allows	O
it	O
to	O
implement	O
,	O
for	O
example	O
,	O
lock-free	B-Operating_System
reference	B-General_Concept
counting	I-General_Concept
in	O
the	O
face	O
of	O
changing	O
object	O
graphs	O
with	O
arbitrary	O
counter	O
reuse	O
(	O
which	O
otherwise	O
requires	O
double	B-Operating_System
compare-and-swap	I-Operating_System
,	O
DCAS	O
)	O
.	O
</s>
<s>
RISC-V	B-Device
provides	O
an	O
architectural	O
guarantee	O
of	O
eventual	O
progress	O
for	O
LL/SC	B-Operating_System
sequences	O
of	O
limited	O
length	O
.	O
</s>
<s>
Some	O
ARM	B-Architecture
implementations	O
define	O
platform	O
dependent	O
blocks	O
,	O
ranging	O
from	O
8	O
bytes	O
to	O
2048	O
bytes	O
,	O
and	O
an	O
LL/SC	B-Operating_System
attempt	O
in	O
any	O
given	O
block	O
fails	O
if	O
there	O
is	O
between	O
the	O
LL	O
and	O
SC	O
a	O
normal	O
memory	O
access	O
inside	O
the	O
same	O
block	O
.	O
</s>
<s>
Other	O
ARM	B-Architecture
implementations	O
fail	O
if	O
there	O
is	O
a	O
modification	O
anywhere	O
in	O
the	O
whole	O
address	O
space	O
.	O
</s>
<s>
LL/SC	B-Operating_System
has	O
two	O
advantages	O
over	O
CAS	O
when	O
designing	O
a	O
load	B-Architecture
–	I-Architecture
store	I-Architecture
architecture	I-Architecture
:	O
reads	O
and	O
writes	O
are	O
separate	O
instructions	O
,	O
as	O
required	O
by	O
the	O
design	O
philosophy	O
(	O
and	O
pipeline	B-General_Concept
architecture	I-General_Concept
)	O
;	O
and	O
both	O
instructions	O
can	O
be	O
performed	O
using	O
only	O
two	O
registers	B-General_Concept
(	O
address	O
and	O
value	O
)	O
,	O
fitting	O
naturally	O
into	O
common	O
2-operand	O
ISAs	O
.	O
</s>
<s>
CAS	O
,	O
on	O
the	O
other	O
hand	O
,	O
requires	O
three	O
registers	B-General_Concept
(	O
address	O
,	O
old	O
value	O
,	O
new	O
value	O
)	O
and	O
a	O
dependency	O
between	O
the	O
value	O
read	O
and	O
the	O
value	O
written	O
.	O
</s>
<s>
x86	B-Operating_System
,	O
being	O
a	O
CISC	B-Architecture
architecture	I-Architecture
,	O
does	O
not	O
have	O
this	O
constraint	O
;	O
though	O
modern	O
chips	O
may	O
well	O
translate	O
a	O
CAS	O
instruction	O
into	O
separate	O
LL/SC	B-Operating_System
micro-operations	B-General_Concept
internally	O
.	O
</s>
<s>
Hardware	O
LL/SC	B-Operating_System
implementations	O
typically	O
do	O
not	O
allow	O
nesting	O
of	O
LL/SC	B-Operating_System
pairs	O
.	O
</s>
<s>
A	O
nesting	O
LL/SC	B-Operating_System
mechanism	O
can	O
be	O
used	O
to	O
provide	O
a	O
MCAS	O
primitive	O
(	O
multi-word	O
CAS	O
,	O
where	O
the	O
words	O
can	O
be	O
scattered	O
)	O
.	O
</s>
<s>
In	O
2013	O
,	O
Trevor	O
Brown	O
,	O
Faith	O
Ellen	O
,	O
and	O
Eric	O
Ruppert	O
implemented	O
in	O
software	O
a	O
multi-address	O
LL/SC	B-Operating_System
extension	O
(	O
which	O
they	O
call	O
LLX/SCX	O
)	O
that	O
relies	O
on	O
automated	O
code	O
generation	O
;	O
they	O
have	O
used	O
it	O
to	O
implement	O
one	O
of	O
the	O
best-performing	O
concurrent	O
binary	B-Language
search	I-Language
tree	I-Language
(	O
actually	O
a	O
chromatic	O
tree	O
)	O
,	O
slightly	O
beating	O
the	O
JDK	B-Language
CAS-based	O
skip	O
list	O
implementation	O
.	O
</s>
