<s>
mutual	B-Operating_System
exclusion	I-Operating_System
in	O
multiprocessor	B-Operating_System
environments	O
.	O
</s>
<s>
Although	O
a	O
correct	O
lock	B-Operating_System
can	O
be	O
implemented	O
with	O
test-and-set	B-Operating_System
,	O
the	O
test	B-Operating_System
and	I-Operating_System
test-and-set	I-Operating_System
optimization	O
lowers	O
resource	B-General_Concept
contention	I-General_Concept
caused	O
by	O
bus	O
locking	B-Operating_System
,	O
especially	O
cache	O
coherency	O
protocol	O
overhead	O
on	O
contended	O
locks	O
.	O
</s>
<s>
Given	O
a	O
lock	B-Operating_System
:	O
</s>
<s>
The	O
difference	O
to	O
the	O
simple	O
test-and-set	B-Operating_System
protocol	O
is	O
the	O
additional	O
spin-loop	O
(	O
the	O
test	O
in	O
test	B-Operating_System
and	I-Operating_System
test-and-set	I-Operating_System
)	O
at	O
the	O
start	O
of	O
the	O
entry	O
protocol	O
,	O
which	O
utilizes	O
ordinary	O
load	O
instructions	O
.	O
</s>
<s>
E.g.	O
,	O
on	O
a	O
system	O
utilizing	O
the	O
MESI	B-General_Concept
cache	O
coherency	O
protocol	O
,	O
the	O
cache	O
line	O
being	O
loaded	O
is	O
moved	O
to	O
the	O
Shared	O
state	O
,	O
whereas	O
a	O
test-and-set	B-Operating_System
instruction	O
or	O
a	O
load-exclusive	O
instruction	O
moves	O
it	O
into	O
the	O
Exclusive	O
state	O
.	O
</s>
<s>
This	O
is	O
particularly	O
advantageous	O
if	O
multiple	O
processors	O
are	O
contending	O
for	O
the	O
same	O
lock	B-Operating_System
:	O
whereas	O
an	O
atomic	O
instruction	O
or	O
load-exclusive	O
instruction	O
requires	O
a	O
coherency-protocol	O
transaction	O
to	O
give	O
that	O
processor	O
exclusive	O
access	O
to	O
the	O
cache	O
line	O
(	O
causing	O
that	O
line	O
to	O
ping-pong	O
between	O
the	O
involved	O
processors	O
)	O
,	O
ordinary	O
loads	O
on	O
a	O
line	O
in	O
Shared	O
state	O
require	O
no	O
protocol	O
transactions	O
at	O
all	O
:	O
processors	O
spinning	O
in	O
the	O
inner	O
loop	O
operate	O
purely	O
locally	O
.	O
</s>
<s>
By	O
using	O
operating-system	O
provided	O
lock	B-Operating_System
objects	O
,	O
such	O
as	O
mutexes	B-Operating_System
,	O
the	O
OS	O
can	O
schedule	O
exactly	O
the	O
unblocked	O
threads	O
.	O
</s>
