<s>
Array-Based	O
Queuing	O
Lock	B-Operating_System
(	O
ABQL	O
)	O
is	O
an	O
advanced	O
lock	B-Operating_System
algorithm	O
that	O
ensures	O
that	O
threads	O
spin	O
on	O
unique	O
memory	O
locations	O
thus	O
ensuring	O
fairness	O
of	O
lock	B-Operating_System
acquisition	O
coupled	O
with	O
improved	O
scalability	O
.	O
</s>
<s>
Synchronization	O
is	O
a	O
major	O
issue	O
in	O
the	O
designing	O
and	O
programming	O
of	O
shared	B-Operating_System
memory	I-Operating_System
multiprocessors	I-Operating_System
.	O
</s>
<s>
The	O
common	O
problem	O
with	O
lock	B-Operating_System
implementations	O
is	O
the	O
high	O
network	O
contention	B-Architecture
due	O
to	O
the	O
processors	O
spinning	O
on	O
a	O
shared	O
synchronization	O
flag	O
or	O
memory	O
location	O
.	O
</s>
<s>
Thus	O
the	O
scalability	O
of	O
the	O
lock	B-Operating_System
is	O
reduced	O
significantly	O
in	O
terms	O
of	O
the	O
number	O
of	O
contending	O
processors	O
.	O
</s>
<s>
The	O
Array	O
Based	O
Queuing	O
Lock	B-Operating_System
is	O
an	O
extension	O
to	O
the	O
ticket	B-Operating_System
lock	I-Operating_System
algorithm	O
which	O
ensures	O
that	O
,	O
on	O
a	O
lock	B-Operating_System
release	O
,	O
only	O
one	O
processor	O
attempts	O
to	O
acquire	O
the	O
lock	B-Operating_System
,	O
decreasing	O
the	O
number	O
of	O
cache	O
misses	O
.	O
</s>
<s>
One	O
analogy	O
used	O
to	O
explain	O
the	O
lock	B-Operating_System
mechanism	O
is	O
the	O
relay	O
race	O
where	O
the	O
athlete	O
passes	O
on	O
the	O
baton	O
to	O
the	O
next	O
athlete	O
in	O
the	O
queue	O
,	O
which	O
ensures	O
that	O
only	O
one	O
athlete	O
acquires	O
the	O
baton	O
at	O
a	O
time	O
.	O
</s>
<s>
ABQL	O
also	O
guarantees	O
fairness	O
in	O
lock	B-Operating_System
acquisition	O
by	O
using	O
a	O
first	B-Operating_System
in	I-Operating_System
,	I-Operating_System
first	I-Operating_System
out	I-Operating_System
(	O
FIFO	B-Operating_System
)	O
queue-based	O
mechanism	O
.	O
</s>
<s>
Additionally	O
,	O
the	O
amount	O
of	O
invalidation	O
is	O
significantly	O
less	O
than	O
ticket-based	O
lock	B-Operating_System
implementations	O
since	O
only	O
one	O
processor	O
incurs	O
a	O
cache	O
miss	O
on	O
a	O
lock	B-Operating_System
release	O
.	O
</s>
<s>
The	O
foremost	O
requirement	O
of	O
the	O
implementation	O
of	O
array	O
based	O
queuing	O
lock	B-Operating_System
is	O
to	O
ensure	O
that	O
all	O
the	O
threads	O
spin	O
on	O
unique	O
memory	O
locations	O
.	O
</s>
<s>
This	O
is	O
achieved	O
with	O
an	O
array	O
of	O
length	O
equal	O
to	O
the	O
number	O
of	O
threads	O
which	O
are	O
in	O
contention	B-Architecture
for	O
the	O
lock	B-Operating_System
.	O
</s>
<s>
The	O
elements	O
of	O
the	O
array	O
are	O
all	O
initialized	O
to	O
0	O
except	O
the	O
first	O
element	O
which	O
is	O
takes	O
the	O
value	O
1	O
,	O
thus	O
ensuring	O
successful	O
lock	B-Operating_System
acquisition	O
by	O
the	O
first	O
thread	O
in	O
the	O
queue	O
.	O
</s>
<s>
On	O
a	O
lock	B-Operating_System
release	O
,	O
the	O
hold	O
is	O
passed	O
to	O
the	O
next	O
thread	O
in	O
queue	O
by	O
setting	O
the	O
next	O
element	O
of	O
the	O
array	O
to	O
1	O
.	O
</s>
<s>
The	O
requests	O
are	O
granted	O
to	O
the	O
threads	O
in	O
FIFO	B-Operating_System
ordering	O
.	O
</s>
<s>
can_serve	O
array	O
represents	O
the	O
unique	O
memory	O
locations	O
that	O
the	O
threads	O
waiting	O
in	O
the	O
queue	O
for	O
the	O
lock	B-Operating_System
acquisitions	O
spin	O
on	O
.	O
</s>
<s>
Initialization	O
of	O
the	O
first	O
element	O
in	O
the	O
array	O
can_serve	O
to	O
1	O
,	O
ensures	O
successful	O
lock	B-Operating_System
acquisition	O
by	O
the	O
first	O
thread	O
in	O
the	O
queue	O
.	O
</s>
<s>
The	O
acquire	O
method	O
uses	O
an	O
atomic	B-General_Concept
operation	I-General_Concept
fetch_and_inc	O
to	O
fetch	O
the	O
next	O
available	O
ticket	O
number	O
(	O
afterwards	O
the	O
ticket	O
number	O
is	O
incremented	O
by	O
1	O
)	O
that	O
the	O
new	O
thread	O
will	O
use	O
to	O
spin	O
on	O
.	O
</s>
<s>
On	O
acquiring	O
the	O
lock	B-Operating_System
the	O
thread	O
enters	O
the	O
critical	B-Operating_System
section	I-Operating_System
of	O
the	O
code	O
.	O
</s>
<s>
On	O
release	O
of	O
a	O
lock	B-Operating_System
by	O
a	O
thread	O
,	O
the	O
control	O
is	O
passed	O
to	O
the	O
next	O
thread	O
by	O
setting	O
the	O
next	O
element	O
in	O
the	O
array	O
can_serve	O
to	O
1	O
.	O
</s>
<s>
The	O
next	O
thread	O
which	O
was	O
waiting	O
to	O
acquire	O
the	O
lock	B-Operating_System
can	O
now	O
do	O
so	O
successfully	O
.	O
</s>
<s>
The	O
working	O
of	O
ABQL	O
can	O
be	O
depicted	O
in	O
the	O
table	O
below	O
by	O
assuming	O
4	O
processors	O
contending	O
to	O
enter	O
the	O
critical	B-Operating_System
section	I-Operating_System
with	O
the	O
assumption	O
that	O
a	O
thread	O
enters	O
the	O
critical	B-Operating_System
section	I-Operating_System
only	O
once	O
.	O
</s>
<s>
Execution	O
Steps	O
can_serve	O
Commentsinitially0[ 1	O
,	O
0	O
,	O
0	O
,	O
0 ]0000initial	O
value	O
of	O
all	O
variables	O
is	O
0	O
P1	O
:	O
fetch_and_inc1[ 1	O
,	O
0	O
,	O
0	O
,	O
0 ]0000	O
P1	O
attempts	O
and	O
successfully	O
acquires	O
the	O
lock	B-Operating_System
P2	O
:	O
fetch_and_inc2[ 1	O
,	O
0	O
,	O
0	O
,	O
0 ]0100	O
P2	O
attempts	O
to	O
acquire	O
the	O
lock	B-Operating_System
P3	O
:	O
fetch_and_inc3[ 1	O
,	O
0	O
,	O
0	O
,	O
0 ]0120	O
P3	O
attempts	O
to	O
acquire	O
the	O
lock	B-Operating_System
P4	O
:	O
fetch_and_inc4[ 1	O
,	O
0	O
,	O
0	O
,	O
0 ]0123	O
P4	O
attempts	O
to	O
acquire	O
the	O
lock	B-Operating_System
P1	O
:	O
can_serve[1]	O
=	O
1	O
;	O
</s>
<s>
can_serve[0]	O
=	O
04[ 0	O
,	O
1	O
,	O
0	O
,	O
0 ]0123	O
P1	O
releases	O
the	O
lock	B-Operating_System
and	O
P2	O
successfully	O
acquires	O
the	O
lock	B-Operating_System
P2	O
:	O
can_serve[2]	O
=	O
1	O
;	O
</s>
<s>
can_serve[1]	O
=	O
04[ 0	O
,	O
0	O
,	O
1	O
,	O
0 ]0123	O
P2	O
releases	O
the	O
lock	B-Operating_System
and	O
P3	O
successfully	O
acquires	O
the	O
lock	B-Operating_System
P3	O
:	O
can_serve[3]	O
=	O
1	O
;	O
</s>
<s>
The	O
following	O
performance	O
criteria	O
can	O
be	O
used	O
to	O
analyse	O
the	O
lock	B-Operating_System
implementations	O
:	O
</s>
<s>
Uncontended	O
lock-acquisition	O
latency	O
-	O
It	O
is	O
defined	O
as	O
the	O
time	O
taken	O
by	O
a	O
thread	O
to	O
acquire	O
a	O
lock	B-Operating_System
when	O
there	O
is	O
no	O
contention	B-Architecture
between	O
threads	O
.	O
</s>
<s>
Due	O
to	O
relatively	O
more	O
number	O
of	O
instructions	O
being	O
executed	O
as	O
opposed	O
to	O
other	O
lock	B-Operating_System
implementations	O
,	O
the	O
uncontented	O
lock	B-Operating_System
acquisition	O
latency	O
for	O
ABQL	O
is	O
high	O
.	O
</s>
<s>
Traffic	O
-	O
It	O
is	O
defined	O
as	O
number	O
of	O
bus	O
transactions	O
generated	O
which	O
is	O
dependent	O
on	O
the	O
number	O
of	O
threads	O
in	O
contention	B-Architecture
for	O
the	O
lock	B-Operating_System
.	O
</s>
<s>
On	O
a	O
lock	B-Operating_System
release	O
,	O
only	O
1	O
cache	O
block	O
is	O
invalidated	O
thus	O
resulting	O
in	O
a	O
single	O
cache	O
miss	O
.	O
</s>
<s>
Fairness	O
-	O
It	O
ensures	O
that	O
all	O
processors	O
waiting	O
to	O
acquire	O
the	O
lock	B-Operating_System
are	O
able	O
to	O
do	O
so	O
in	O
the	O
order	O
in	O
which	O
their	O
requests	O
are	O
issued	O
.	O
</s>
<s>
Due	O
to	O
the	O
threads	O
waiting	O
in	O
a	O
queue	O
to	O
acquire	O
a	O
lock	B-Operating_System
with	O
each	O
thread	O
spinning	O
on	O
an	O
individual	O
memory	O
location	O
,	O
fairness	O
is	O
ensured	O
.	O
</s>
<s>
Storage	O
-	O
The	O
amount	O
of	O
memory	O
required	O
for	O
the	O
processing	O
of	O
the	O
lock	B-Operating_System
mechanism	O
.	O
</s>
<s>
ABQL	O
offers	O
improved	O
scalability	O
as	O
each	O
lock	B-Operating_System
acquisition	O
or	O
release	O
triggers	O
only	O
1	O
cache	O
miss	O
resulting	O
in	O
only	O
cache	O
block	O
suffering	O
from	O
a	O
cache	O
miss	O
to	O
reload	O
the	O
block	O
.	O
</s>
<s>
Fairness	O
of	O
lock	B-Operating_System
acquisitions	O
is	O
ensured	O
due	O
to	O
the	O
use	O
of	O
queue	O
which	O
ensures	O
that	O
the	O
threads	O
acquire	O
the	O
lock	B-Operating_System
successfully	O
in	O
the	O
order	O
in	O
which	O
their	O
threads	O
are	O
issued	O
.	O
</s>
<s>
ABQL	O
should	O
not	O
be	O
used	O
with	O
threads	O
that	O
can	O
be	O
suspended	O
(	O
sleep	O
or	O
context	B-Operating_System
switch	I-Operating_System
)	O
as	O
any	O
thread	O
not	O
immediately	O
ready	O
to	O
acquire	O
the	O
lock	B-Operating_System
will	O
increase	O
the	O
latency	O
of	O
all	O
those	O
behind	O
it	O
waiting	O
for	O
the	O
lock	B-Operating_System
.	O
</s>
