<s>
In	O
parallel	B-Operating_System
computing	I-Operating_System
,	O
work	B-Operating_System
stealing	I-Operating_System
is	O
a	O
scheduling	O
strategy	O
for	O
multithreaded	B-Operating_System
computer	O
programs	O
.	O
</s>
<s>
It	O
solves	O
the	O
problem	O
of	O
executing	O
a	O
dynamically	O
multithreaded	B-Operating_System
computation	O
,	O
one	O
that	O
can	O
"	O
spawn	O
"	O
new	O
threads	B-Operating_System
of	O
execution	O
,	O
on	O
a	O
statically	O
multithreaded	B-Operating_System
computer	O
,	O
with	O
a	O
fixed	O
number	O
of	O
processors	O
(	O
or	O
cores	O
)	O
.	O
</s>
<s>
In	O
a	O
work	B-Operating_System
stealing	I-Operating_System
scheduler	O
,	O
each	O
processor	O
in	O
a	O
computer	O
system	O
has	O
a	O
queue	O
of	O
work	O
items	O
(	O
computational	O
tasks	O
,	O
threads	B-Operating_System
)	O
to	O
perform	O
.	O
</s>
<s>
In	O
effect	O
,	O
work	B-Operating_System
stealing	I-Operating_System
distributes	O
the	O
scheduling	O
work	O
over	O
idle	O
processors	O
,	O
and	O
as	O
long	O
as	O
all	O
processors	O
have	O
work	O
to	O
do	O
,	O
no	O
scheduling	O
overhead	O
occurs	O
.	O
</s>
<s>
Work	B-Operating_System
stealing	I-Operating_System
contrasts	O
with	O
work	O
sharing	O
,	O
another	O
popular	O
scheduling	O
approach	O
for	O
dynamic	O
multithreading	B-Operating_System
,	O
where	O
each	O
work	O
item	O
is	O
scheduled	O
onto	O
a	O
processor	O
when	O
it	O
is	O
spawned	O
.	O
</s>
<s>
Compared	O
to	O
this	O
approach	O
,	O
work	B-Operating_System
stealing	I-Operating_System
reduces	O
the	O
amount	O
of	O
process	B-Operating_System
migration	I-Operating_System
between	O
processors	O
,	O
because	O
no	O
such	O
migration	O
occurs	O
when	O
all	O
processors	O
have	O
work	O
to	O
do	O
.	O
</s>
<s>
The	O
idea	O
of	O
work	B-Operating_System
stealing	I-Operating_System
goes	O
back	O
to	O
the	O
implementation	O
of	O
the	O
Multilisp	B-Language
programming	I-Language
language	I-Language
and	O
work	O
on	O
parallel	O
functional	B-Language
programming	I-Language
languages	I-Language
in	O
the	O
1980s	O
.	O
</s>
<s>
It	O
is	O
employed	O
in	O
the	O
scheduler	O
for	O
the	O
Cilk	B-Language
programming	I-Language
language	I-Language
,	O
the	O
Java	B-Language
fork/join	O
framework	O
,	O
the	O
.NET	O
Task	O
Parallel	O
Library	B-Library
,	O
and	O
the	O
Rust	B-Application
Tokio	B-Application
runtime	I-Application
.	O
</s>
<s>
Work	B-Operating_System
stealing	I-Operating_System
is	O
designed	O
for	O
a	O
"	O
strict	O
"	O
fork	B-Operating_System
–	I-Operating_System
join	I-Operating_System
model	I-Operating_System
of	O
parallel	B-Operating_System
computation	I-Operating_System
,	O
which	O
means	O
that	O
a	O
computation	O
can	O
be	O
viewed	O
as	O
a	O
directed	O
acyclic	O
graph	O
with	O
a	O
single	O
source	O
(	O
start	O
of	O
computation	O
)	O
and	O
a	O
single	O
sink	O
(	O
end	O
of	O
computation	O
)	O
.	O
</s>
<s>
Forks	O
produce	O
multiple	O
logically	O
parallel	B-Operating_System
computations	I-Operating_System
,	O
variously	O
called	O
"	O
threads	B-Operating_System
"	O
or	O
"	O
strands	O
"	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
consider	O
the	O
following	O
trivial	O
fork	O
–	O
join	O
program	O
in	O
Cilk-like	O
syntax	O
:	O
</s>
<s>
The	O
randomized	B-General_Concept
version	O
of	O
the	O
work	B-Operating_System
stealing	I-Operating_System
algorithm	O
presented	O
by	O
Blumofe	O
and	O
Leiserson	O
maintains	O
several	O
threads	B-Operating_System
of	O
execution	O
and	O
schedules	O
these	O
onto	O
processors	O
.	O
</s>
<s>
Each	O
of	O
the	O
processors	O
has	O
a	O
double-ended	B-Application
queue	I-Application
(	O
deque	B-Application
)	O
of	O
threads	B-Operating_System
.	O
</s>
<s>
Call	O
the	O
ends	O
of	O
the	O
deque	B-Application
"	O
top	O
"	O
and	O
"	O
bottom	O
"	O
.	O
</s>
<s>
Each	O
processor	O
that	O
has	O
a	O
current	O
thread	B-Operating_System
to	O
execute	O
,	O
executes	O
the	O
instructions	O
in	O
the	O
thread	B-Operating_System
one	O
by	O
one	O
,	O
until	O
it	O
encounters	O
an	O
instruction	O
that	O
causes	O
one	O
of	O
four	O
"	O
special	O
"	O
behaviors	O
:	O
</s>
<s>
A	O
spawn	O
instruction	O
causes	O
a	O
new	O
thread	B-Operating_System
to	O
be	O
created	O
.	O
</s>
<s>
The	O
current	O
thread	B-Operating_System
is	O
placed	O
at	O
the	O
bottom	O
of	O
the	O
deque	B-Application
,	O
and	O
the	O
processor	O
starts	O
executing	O
the	O
new	O
thread	B-Operating_System
.	O
</s>
<s>
A	O
stalling	O
instruction	O
is	O
one	O
that	O
temporarily	O
halts	O
execution	O
of	O
its	O
thread	B-Operating_System
.	O
</s>
<s>
The	O
processor	O
pops	O
a	O
thread	B-Operating_System
off	O
the	O
bottom	O
of	O
its	O
deque	B-Application
and	O
starts	O
executing	O
that	O
thread	B-Operating_System
.	O
</s>
<s>
If	O
its	O
deque	B-Application
is	O
empty	O
,	O
it	O
starts	O
work	B-Operating_System
stealing	I-Operating_System
,	O
explained	O
below	O
.	O
</s>
<s>
An	O
instruction	O
may	O
cause	O
a	O
thread	B-Operating_System
to	O
die	O
.	O
</s>
<s>
An	O
instruction	O
may	O
enable	O
another	O
thread	B-Operating_System
.	O
</s>
<s>
The	O
other	O
thread	B-Operating_System
is	O
pushed	O
onto	O
the	O
bottom	O
of	O
the	O
deque	B-Application
,	O
but	O
the	O
processor	O
continues	O
execution	O
of	O
its	O
current	O
thread	B-Operating_System
.	O
</s>
<s>
Initially	O
,	O
a	O
computation	O
consists	O
of	O
a	O
single	B-Operating_System
thread	I-Operating_System
and	O
is	O
assigned	O
to	O
some	O
processor	O
,	O
while	O
the	O
other	O
processors	O
start	O
off	O
idle	O
.	O
</s>
<s>
Any	O
processor	O
that	O
becomes	O
idle	O
starts	O
the	O
actual	O
process	O
of	O
work	B-Operating_System
stealing	I-Operating_System
,	O
which	O
means	O
the	O
following	O
:	O
</s>
<s>
if	O
the	O
other	O
processor	O
's	O
deque	B-Application
is	O
non-empty	O
,	O
it	O
pops	O
the	O
top-most	O
thread	B-Operating_System
off	O
the	O
deque	B-Application
and	O
starts	O
executing	O
that	O
;	O
</s>
<s>
Note	O
that	O
,	O
in	O
the	O
rule	O
for	O
spawn	O
,	O
Blumofe	O
and	O
Leiserson	O
suggest	O
that	O
the	O
"	O
parent	O
"	O
thread	B-Operating_System
execute	O
its	O
new	O
thread	B-Operating_System
,	O
as	O
if	O
performing	O
a	O
function	O
call	O
(	O
in	O
the	O
C-like	O
program	O
,	O
the	O
function	O
call	O
to	O
completes	O
before	O
the	O
call	O
to	O
is	O
performed	O
)	O
.	O
</s>
<s>
This	O
is	O
called	O
"	O
continuation	O
stealing	O
"	O
,	O
because	O
the	O
continuation	O
of	O
the	O
function	O
can	O
be	O
stolen	O
while	O
the	O
spawned	O
thread	B-Operating_System
is	O
executed	O
,	O
and	O
is	O
the	O
scheduling	O
algorithm	O
used	O
in	O
Cilk	B-Language
Plus	O
.	O
</s>
<s>
It	O
is	O
not	O
the	O
only	O
way	O
to	O
implement	O
work	B-Operating_System
stealing	I-Operating_System
;	O
the	O
alternative	O
strategy	O
is	O
called	O
"	O
child	O
stealing	O
"	O
and	O
is	O
easier	O
to	O
implement	O
as	O
a	O
library	B-Library
,	O
without	O
compiler	B-Language
support	O
.	O
</s>
<s>
Child	O
stealing	O
is	O
used	O
by	O
Threading	B-Application
Building	I-Application
Blocks	I-Application
,	O
Microsoft	O
's	O
Task	O
Parallel	O
Library	B-Library
and	O
OpenMP	B-Application
,	O
although	O
the	O
latter	O
gives	O
the	O
programmer	O
control	O
over	O
which	O
strategy	O
is	O
used	O
.	O
</s>
<s>
Several	O
variants	O
of	O
work	B-Operating_System
stealing	I-Operating_System
have	O
been	O
proposed	O
.	O
</s>
<s>
The	O
randomized	B-General_Concept
variant	O
due	O
to	O
Blumofe	O
and	O
Leiserson	O
executes	O
a	O
parallel	B-Operating_System
computation	I-Operating_System
in	O
expected	O
time	O
on	O
processors	O
;	O
here	O
,	O
is	O
the	O
work	O
,	O
or	O
the	O
amount	O
of	O
time	O
required	O
to	O
run	O
the	O
computation	O
on	O
a	O
serial	O
computer	O
,	O
and	O
is	O
the	O
span	O
,	O
the	O
amount	O
of	O
time	O
required	O
on	O
an	O
infinitely	O
parallel	B-Operating_System
machine	I-Operating_System
.	O
</s>
<s>
A	O
computation	O
scheduled	O
by	O
the	O
Blumofe	O
–	O
Leiserson	O
version	O
of	O
work	B-Operating_System
stealing	I-Operating_System
uses	O
stack	B-General_Concept
space	I-General_Concept
,	O
if	O
were	O
the	O
stack	O
usage	O
of	O
the	O
same	O
computation	O
on	O
a	O
single	O
processor	O
,	O
fitting	O
the	O
authors	O
 '	O
own	O
earlier	O
definition	O
of	O
space	O
efficiency	O
.	O
</s>
<s>
The	O
work	B-Operating_System
stealing	I-Operating_System
algorithm	O
as	O
outlined	O
earlier	O
,	O
and	O
its	O
analysis	O
,	O
assume	O
a	O
computing	O
environment	O
where	O
a	O
computation	O
is	O
scheduled	O
onto	O
a	O
set	O
of	O
dedicated	O
processors	O
.	O
</s>
<s>
In	O
a	O
multiprogramming	O
(	O
multi-tasking	O
)	O
environment	O
,	O
the	O
algorithm	O
must	O
be	O
modified	O
to	O
instead	O
schedule	O
computation	O
tasks	O
onto	O
a	O
pool	B-Operating_System
of	I-Operating_System
worker	I-Operating_System
threads	I-Operating_System
,	O
which	O
in	O
turn	O
are	O
scheduled	O
onto	O
the	O
actual	O
processors	O
by	O
an	O
operating	B-General_Concept
system	I-General_Concept
scheduler	O
.	O
</s>
<s>
At	O
any	O
given	O
time	O
,	O
the	O
OS	O
scheduler	O
will	O
assign	O
to	O
the	O
work	B-Operating_System
stealing	I-Operating_System
process	O
some	O
number	O
of	O
the	O
processors	O
in	O
the	O
computer	O
,	O
because	O
other	O
processes	O
may	O
be	O
using	O
the	O
remaining	O
processors	O
.	O
</s>
<s>
In	O
this	O
setting	O
,	O
work	B-Operating_System
stealing	I-Operating_System
with	O
a	O
pool	O
of	O
worker	O
threads	B-Operating_System
has	O
the	O
problem	O
that	O
workers	O
acting	O
as	O
thieves	O
may	O
cause	O
livelock	B-Application
:	O
they	O
may	O
block	O
the	O
execution	O
of	O
workers	O
that	O
would	O
actually	O
spawn	O
useful	O
tasks	O
.	O
</s>
<s>
Its	O
queues	O
are	O
non-blocking	B-Operating_System
.	O
</s>
<s>
While	O
on	O
dedicated	O
processors	O
,	O
access	O
to	O
the	O
queues	O
can	O
be	O
synchronized	O
using	O
locks	B-Operating_System
,	O
this	O
is	O
not	O
advisable	O
in	O
a	O
multiprogramming	O
environment	O
since	O
the	O
operating	B-General_Concept
system	I-General_Concept
might	O
preempt	B-Operating_System
the	O
worker	O
thread	B-Operating_System
holding	O
the	O
lock	O
,	O
blocking	O
the	O
progress	O
of	O
any	O
other	O
workers	O
that	O
try	O
to	O
access	O
the	O
same	O
queue	O
.	O
</s>
<s>
Before	O
each	O
attempt	O
to	O
steal	O
work	O
,	O
a	O
worker	O
thread	B-Operating_System
calls	O
a	O
""	O
system	O
call	O
that	O
yields	O
the	O
processor	O
on	O
which	O
it	O
is	O
scheduled	O
to	O
the	O
OS	O
,	O
in	O
order	O
to	O
prevent	O
starvation	B-Operating_System
.	O
</s>
<s>
Attempts	O
to	O
improve	O
on	O
the	O
multiprogramming	O
work	O
stealer	O
have	O
focused	O
on	O
cache	B-General_Concept
locality	I-General_Concept
issues	O
and	O
improved	O
queue	O
data	O
structures	O
.	O
</s>
<s>
Several	O
scheduling	O
algorithms	O
for	O
dynamically	O
multithreaded	B-Operating_System
computations	O
compete	O
with	O
work	B-Operating_System
stealing	I-Operating_System
.	O
</s>
<s>
Besides	O
the	O
traditional	O
work	O
sharing	O
approach	O
,	O
there	O
is	O
a	O
scheduler	O
called	O
parallel	O
depth-first	O
(	O
PDF	O
)	O
that	O
improves	O
on	O
the	O
space	O
bounds	O
of	O
work	B-Operating_System
stealing	I-Operating_System
,	O
as	O
well	O
giving	O
better	O
performance	O
in	O
some	O
situations	O
where	O
the	O
cores	O
of	O
a	O
chip	B-Architecture
multiprocessor	I-Architecture
share	O
a	O
cache	O
.	O
</s>
