<s>
In	O
parallel	B-Operating_System
computing	I-Operating_System
,	O
the	O
fork	B-Operating_System
–	I-Operating_System
join	I-Operating_System
model	I-Operating_System
is	O
a	O
way	O
of	O
setting	O
up	O
and	O
executing	O
parallel	B-Operating_System
programs	I-Operating_System
,	O
such	O
that	O
execution	O
branches	O
off	O
in	O
parallel	O
at	O
designated	O
points	O
in	O
the	O
program	O
,	O
to	O
"	O
join	O
"	O
(	O
merge	O
)	O
at	O
a	O
subsequent	O
point	O
and	O
resume	O
sequential	O
execution	O
.	O
</s>
<s>
By	O
nesting	O
fork	O
–	O
join	O
computations	O
recursively	O
,	O
one	O
obtains	O
a	O
parallel	O
version	O
of	O
the	O
divide	B-Algorithm
and	I-Algorithm
conquer	I-Algorithm
paradigm	I-Algorithm
,	O
expressed	O
by	O
the	O
following	O
generic	O
pseudocode	B-Language
:	O
</s>
<s>
The	O
simple	O
parallel	O
merge	B-Algorithm
sort	I-Algorithm
of	O
CLRS	O
is	O
a	O
fork	O
–	O
join	O
algorithm	O
.	O
</s>
<s>
mergesort(A, lo, hi )	O
:	O
</s>
<s>
The	O
first	O
recursive	O
call	O
is	O
"	O
forked	O
off	O
"	O
,	O
meaning	O
that	O
its	O
execution	O
may	O
run	O
in	O
parallel	O
(	O
in	O
a	O
separate	O
thread	B-Operating_System
)	O
with	O
the	O
following	O
part	O
of	O
the	O
function	O
,	O
up	O
to	O
the	O
that	O
causes	O
all	O
threads	B-Operating_System
to	O
synchronize	O
.	O
</s>
<s>
While	O
the	O
may	O
look	O
like	O
a	O
barrier	B-Operating_System
,	O
it	O
is	O
different	O
because	O
the	O
threads	B-Operating_System
will	O
continue	O
to	O
work	O
after	O
a	O
barrier	B-Operating_System
,	O
while	O
after	O
a	O
only	O
one	O
thread	B-Operating_System
continues	O
.	O
</s>
<s>
The	O
second	O
recursive	O
call	O
is	O
not	O
a	O
fork	O
in	O
the	O
pseudocode	B-Language
above	O
;	O
this	O
is	O
intentional	O
,	O
as	O
forking	O
tasks	O
may	O
come	O
at	O
an	O
expense	O
.	O
</s>
<s>
Implementations	O
of	O
the	O
fork	B-Operating_System
–	I-Operating_System
join	I-Operating_System
model	I-Operating_System
will	O
typically	O
fork	O
tasks	O
,	O
fibers	O
or	O
lightweight	O
threads	B-Operating_System
,	O
not	O
operating-system-level	O
"	O
heavyweight	O
"	O
threads	B-Operating_System
or	O
processes	O
,	O
and	O
use	O
a	O
thread	B-Operating_System
pool	I-Operating_System
to	O
execute	O
these	O
tasks	O
:	O
the	O
fork	O
primitive	O
allows	O
the	O
programmer	O
to	O
specify	O
potential	O
parallelism	B-Operating_System
,	O
which	O
the	O
implementation	O
then	O
maps	O
onto	O
actual	O
parallel	O
execution	O
.	O
</s>
<s>
The	O
reason	O
for	O
this	O
design	O
is	O
that	O
creating	O
new	O
threads	B-Operating_System
tends	O
to	O
result	O
in	O
too	O
much	O
overhead	O
.	O
</s>
<s>
The	O
lightweight	O
threads	B-Operating_System
used	O
in	O
fork	O
–	O
join	O
programming	O
will	O
typically	O
have	O
their	O
own	O
scheduler	O
(	O
typically	O
a	O
work	B-Operating_System
stealing	I-Operating_System
one	O
)	O
that	O
maps	O
them	O
onto	O
the	O
underlying	O
thread	B-Operating_System
pool	I-Operating_System
.	O
</s>
<s>
This	O
scheduler	O
can	O
be	O
much	O
simpler	O
than	O
a	O
fully	O
featured	O
,	O
preemptive	B-Operating_System
operating	O
system	O
scheduler	O
:	O
general-purpose	O
thread	B-Operating_System
schedulers	O
must	O
deal	O
with	O
blocking	O
for	O
locks	B-Operating_System
,	O
but	O
in	O
the	O
fork	O
–	O
join	O
paradigm	O
,	O
threads	B-Operating_System
only	O
block	O
at	O
the	O
join	O
point	O
.	O
</s>
<s>
Fork	O
–	O
join	O
is	O
the	O
main	O
model	O
of	O
parallel	O
execution	O
in	O
the	O
OpenMP	B-Application
framework	O
,	O
although	O
OpenMP	B-Application
implementations	O
may	O
or	O
may	O
not	O
support	O
nesting	O
of	O
parallel	O
sections	O
.	O
</s>
<s>
It	O
is	O
also	O
supported	O
by	O
the	O
Java	B-Language
concurrency	I-Language
framework	O
,	O
the	O
Task	O
Parallel	O
Library	O
for	O
.NET	O
,	O
and	O
Intel	O
's	O
Threading	B-Application
Building	I-Application
Blocks	I-Application
(	O
TBB	O
)	O
.	O
</s>
<s>
The	O
Cilk	B-Language
programming	I-Language
language	I-Language
has	O
language-level	O
support	O
for	O
fork	O
and	O
join	O
,	O
in	O
the	O
form	O
of	O
the	O
spawn	O
and	O
sync	O
keywords	O
,	O
or	O
cilk_spawn	O
and	O
cilk_sync	O
in	O
Cilk	B-Language
Plus	O
.	O
</s>
