<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
thread	B-Operating_System
of	I-Operating_System
execution	I-Operating_System
is	O
the	O
smallest	O
sequence	O
of	O
programmed	O
instructions	O
that	O
can	O
be	O
managed	O
independently	O
by	O
a	O
scheduler	O
,	O
which	O
is	O
typically	O
a	O
part	O
of	O
the	O
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
The	O
implementation	O
of	O
threads	B-Operating_System
and	O
processes	B-Operating_System
differs	O
between	O
operating	B-General_Concept
systems	I-General_Concept
.	O
</s>
<s>
In	O
Modern	O
Operating	B-General_Concept
Systems	I-General_Concept
,	O
Tanenbaum	O
shows	O
that	O
many	O
distinct	O
models	O
of	O
process	B-Operating_System
organization	O
are	O
possible	O
.	O
</s>
<s>
In	O
many	O
cases	O
,	O
a	O
thread	B-Operating_System
is	O
a	O
component	O
of	O
a	O
process	B-Operating_System
.	O
</s>
<s>
The	O
multiple	O
threads	B-Operating_System
of	O
a	O
given	O
process	B-Operating_System
may	O
be	O
executed	O
concurrently	B-Architecture
(	O
via	O
multithreading	B-General_Concept
capabilities	O
)	O
,	O
sharing	O
resources	B-General_Concept
such	O
as	O
memory	B-General_Concept
,	O
while	O
different	O
processes	B-Operating_System
do	O
not	O
share	O
these	O
resources	B-General_Concept
.	O
</s>
<s>
In	O
particular	O
,	O
the	O
threads	B-Operating_System
of	O
a	O
process	B-Operating_System
share	O
its	O
executable	O
code	O
and	O
the	O
values	O
of	O
its	O
dynamically	O
allocated	O
variables	O
and	O
non-thread-local	O
global	O
variables	O
at	O
any	O
given	O
time	O
.	O
</s>
<s>
Threads	B-Operating_System
made	O
an	O
early	O
appearance	O
under	O
the	O
name	O
of	O
"	O
tasks	O
"	O
in	O
OS/360	O
Multiprogramming	O
with	O
a	O
Variable	O
Number	O
of	O
Tasks	O
(	O
MVT	O
)	O
in	O
1967	O
.	O
</s>
<s>
Saltzer	O
(	O
1966	O
)	O
credits	O
Victor	O
A	O
.	O
Vyssotsky	O
with	O
the	O
term	O
"	O
thread	B-Operating_System
"	O
.	O
</s>
<s>
The	O
use	O
of	O
threads	B-Operating_System
in	O
software	O
applications	O
became	O
more	O
common	O
in	O
the	O
early	O
2000s	O
as	O
CPUs	O
began	O
to	O
utilize	O
multiple	O
cores	O
.	O
</s>
<s>
Applications	O
wishing	O
to	O
take	O
advantage	O
of	O
multiple	O
cores	O
for	O
performance	O
advantages	O
were	O
required	O
to	O
employ	O
concurrency	B-Architecture
to	O
utilize	O
the	O
multiple	O
cores	O
.	O
</s>
<s>
Scheduling	O
can	O
be	O
done	O
at	O
the	O
kernel	B-Operating_System
level	O
or	O
user	O
level	O
,	O
and	O
multitasking	B-Operating_System
can	O
be	O
done	O
preemptively	B-Operating_System
or	O
cooperatively	B-Operating_System
.	O
</s>
<s>
At	O
the	O
kernel	B-Operating_System
level	O
,	O
a	O
process	B-Operating_System
contains	O
one	O
or	O
more	O
kernel	B-Operating_System
threads	B-Operating_System
,	O
which	O
share	O
the	O
process	B-Operating_System
's	O
resources	B-General_Concept
,	O
such	O
as	O
memory	B-General_Concept
and	O
file	O
handles	O
–	O
a	O
process	B-Operating_System
is	O
a	O
unit	O
of	O
resources	B-General_Concept
,	O
while	O
a	O
thread	B-Operating_System
is	O
a	O
unit	O
of	O
scheduling	O
and	O
execution	B-General_Concept
.	O
</s>
<s>
Kernel	B-Operating_System
scheduling	O
is	O
typically	O
uniformly	O
done	O
preemptively	B-Operating_System
or	O
,	O
less	O
commonly	O
,	O
cooperatively	B-Operating_System
.	O
</s>
<s>
At	O
the	O
user	O
level	O
a	O
process	B-Operating_System
such	O
as	O
a	O
runtime	B-Device
system	I-Device
can	O
itself	O
schedule	O
multiple	O
threads	B-Operating_System
of	O
execution	B-General_Concept
.	O
</s>
<s>
If	O
these	O
do	O
not	O
share	O
data	O
,	O
as	O
in	O
Erlang	O
,	O
they	O
are	O
usually	O
analogously	O
called	O
processes	B-Operating_System
,	O
while	O
if	O
they	O
share	O
data	O
they	O
are	O
usually	O
called	O
(	O
user	O
)	O
threads	B-Operating_System
,	O
particularly	O
if	O
preemptively	B-Operating_System
scheduled	O
.	O
</s>
<s>
Cooperatively	B-Operating_System
scheduled	I-Operating_System
user	O
threads	B-Operating_System
are	O
known	O
as	O
fibers	B-Operating_System
;	O
different	O
processes	B-Operating_System
may	O
schedule	O
user	O
threads	B-Operating_System
differently	O
.	O
</s>
<s>
User	O
threads	B-Operating_System
may	O
be	O
executed	O
by	O
kernel	B-Operating_System
threads	B-Operating_System
in	O
various	O
ways	O
(	O
one-to-one	O
,	O
many-to-one	O
,	O
many-to-many	O
)	O
.	O
</s>
<s>
The	O
term	O
"	O
light-weight	B-Operating_System
process	I-Operating_System
"	O
variously	O
refers	O
to	O
user	O
threads	B-Operating_System
or	O
to	O
kernel	B-Operating_System
mechanisms	O
for	O
scheduling	O
user	O
threads	B-Operating_System
onto	O
kernel	B-Operating_System
threads	B-Operating_System
.	O
</s>
<s>
A	O
process	B-Operating_System
is	O
a	O
"	O
heavyweight	O
"	O
unit	O
of	O
kernel	B-Operating_System
scheduling	O
,	O
as	O
creating	O
,	O
destroying	O
,	O
and	O
switching	O
processes	B-Operating_System
is	O
relatively	O
expensive	O
.	O
</s>
<s>
Processes	B-Operating_System
own	O
resources	B-General_Concept
allocated	O
by	O
the	O
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
Resources	B-General_Concept
include	O
memory	B-General_Concept
(	O
for	O
both	O
code	O
and	O
data	O
)	O
,	O
file	O
handles	O
,	O
sockets	O
,	O
device	O
handles	O
,	O
windows	O
,	O
and	O
a	O
process	B-Operating_System
control	I-Operating_System
block	I-Operating_System
.	O
</s>
<s>
Processes	B-Operating_System
are	O
isolated	O
by	O
process	B-Operating_System
isolation	O
,	O
and	O
do	O
not	O
share	O
address	B-General_Concept
spaces	I-General_Concept
or	O
file	O
resources	B-General_Concept
except	O
through	O
explicit	O
methods	O
such	O
as	O
inheriting	O
file	O
handles	O
or	O
shared	B-Operating_System
memory	I-Operating_System
segments	O
,	O
or	O
mapping	O
the	O
same	O
file	O
in	O
a	O
shared	O
way	O
–	O
see	O
interprocess	B-Operating_System
communication	I-Operating_System
.	O
</s>
<s>
Creating	O
or	O
destroying	O
a	O
process	B-Operating_System
is	O
relatively	O
expensive	O
,	O
as	O
resources	B-General_Concept
must	O
be	O
acquired	O
or	O
released	O
.	O
</s>
<s>
Processes	B-Operating_System
are	O
typically	O
preemptively	B-Operating_System
multitasked	O
,	O
and	O
process	B-Operating_System
switching	O
is	O
relatively	O
expensive	O
,	O
beyond	O
basic	O
cost	O
of	O
context	B-Operating_System
switching	I-Operating_System
,	O
due	O
to	O
issues	O
such	O
as	O
cache	O
flushing	O
(	O
in	O
particular	O
,	O
process	B-Operating_System
switching	O
changes	O
virtual	O
memory	B-General_Concept
addressing	O
,	O
causing	O
invalidation	O
and	O
thus	O
flushing	O
of	O
an	O
untagged	O
translation	B-Architecture
lookaside	I-Architecture
buffer	I-Architecture
,	O
notably	O
on	O
x86	B-Operating_System
)	O
.	O
</s>
<s>
A	O
kernel	B-Operating_System
thread	B-Operating_System
is	O
a	O
"	O
lightweight	O
"	O
unit	O
of	O
kernel	B-Operating_System
scheduling	O
.	O
</s>
<s>
At	O
least	O
one	O
kernel	B-Operating_System
thread	B-Operating_System
exists	O
within	O
each	O
process	B-Operating_System
.	O
</s>
<s>
If	O
multiple	O
kernel	B-Operating_System
threads	B-Operating_System
exist	O
within	O
a	O
process	B-Operating_System
,	O
then	O
they	O
share	O
the	O
same	O
memory	B-General_Concept
and	O
file	O
resources	B-General_Concept
.	O
</s>
<s>
Kernel	B-Operating_System
threads	B-Operating_System
are	O
preemptively	B-Operating_System
multitasked	O
if	O
the	O
operating	B-General_Concept
system	I-General_Concept
's	O
process	B-Operating_System
scheduler	O
is	O
preemptive	O
.	O
</s>
<s>
Kernel	B-Operating_System
threads	B-Operating_System
do	O
not	O
own	O
resources	B-General_Concept
except	O
for	O
a	O
stack	B-General_Concept
,	O
a	O
copy	O
of	O
the	O
registers	B-General_Concept
including	O
the	O
program	B-General_Concept
counter	I-General_Concept
,	O
and	O
thread-local	O
storage	O
(	O
if	O
any	O
)	O
,	O
and	O
are	O
thus	O
relatively	O
cheap	O
to	O
create	O
and	O
destroy	O
.	O
</s>
<s>
Thread	B-Operating_System
switching	O
is	O
also	O
relatively	O
cheap	O
:	O
it	O
requires	O
a	O
context	B-Operating_System
switch	I-Operating_System
(	O
saving	O
and	O
restoring	O
registers	B-General_Concept
and	O
stack	B-General_Concept
pointer	O
)	O
,	O
but	O
does	O
not	O
change	O
virtual	O
memory	B-General_Concept
and	O
is	O
thus	O
cache-friendly	O
(	O
leaving	O
TLB	O
valid	O
)	O
.	O
</s>
<s>
The	O
kernel	B-Operating_System
can	O
assign	O
one	O
thread	B-Operating_System
to	O
each	O
logical	O
core	O
in	O
a	O
system	O
(	O
because	O
each	O
processor	O
splits	O
itself	O
up	O
into	O
multiple	O
logical	O
cores	O
if	O
it	O
supports	O
multithreading	B-General_Concept
,	O
or	O
only	O
supports	O
one	O
logical	O
core	O
per	O
physical	O
core	O
if	O
it	O
does	O
not	O
)	O
,	O
and	O
can	O
swap	O
out	O
threads	B-Operating_System
that	O
get	O
blocked	O
.	O
</s>
<s>
However	O
,	O
kernel	B-Operating_System
threads	B-Operating_System
take	O
much	O
longer	O
than	O
user	O
threads	B-Operating_System
to	O
be	O
swapped	O
.	O
</s>
<s>
Threads	B-Operating_System
are	O
sometimes	O
implemented	O
in	O
userspace	B-Operating_System
libraries	O
,	O
thus	O
called	O
user	O
threads	B-Operating_System
.	O
</s>
<s>
The	O
kernel	B-Operating_System
is	O
unaware	O
of	O
them	O
,	O
so	O
they	O
are	O
managed	O
and	O
scheduled	O
in	O
userspace	B-Operating_System
.	O
</s>
<s>
Some	O
implementations	O
base	O
their	O
user	O
threads	B-Operating_System
on	O
top	O
of	O
several	O
kernel	B-Operating_System
threads	B-Operating_System
,	O
to	O
benefit	O
from	O
multi-processor	B-Operating_System
machines	O
(	O
M:N	O
model	O
)	O
.	O
</s>
<s>
User	O
threads	B-Operating_System
as	O
implemented	O
by	O
virtual	B-Architecture
machines	I-Architecture
are	O
also	O
called	O
green	B-Operating_System
threads	I-Operating_System
.	O
</s>
<s>
As	O
user	O
thread	B-Operating_System
implementations	O
are	O
typically	O
entirely	O
in	O
userspace	B-Operating_System
,	O
context	B-Operating_System
switching	I-Operating_System
between	O
user	O
threads	B-Operating_System
within	O
the	O
same	O
process	B-Operating_System
is	O
extremely	O
efficient	O
because	O
it	O
does	O
not	O
require	O
any	O
interaction	O
with	O
the	O
kernel	B-Operating_System
at	O
all	O
:	O
a	O
context	B-Operating_System
switch	I-Operating_System
can	O
be	O
performed	O
by	O
locally	O
saving	O
the	O
CPU	B-General_Concept
registers	I-General_Concept
used	O
by	O
the	O
currently	O
executing	O
user	O
thread	B-Operating_System
or	O
fiber	O
and	O
then	O
loading	O
the	O
registers	B-General_Concept
required	O
by	O
the	O
user	O
thread	B-Operating_System
or	O
fiber	O
to	O
be	O
executed	O
.	O
</s>
<s>
Since	O
scheduling	O
occurs	O
in	O
userspace	B-Operating_System
,	O
the	O
scheduling	O
policy	O
can	O
be	O
more	O
easily	O
tailored	O
to	O
the	O
requirements	O
of	O
the	O
program	B-Application
's	O
workload	O
.	O
</s>
<s>
However	O
,	O
the	O
use	O
of	O
blocking	O
system	O
calls	O
in	O
user	O
threads	B-Operating_System
(	O
as	O
opposed	O
to	O
kernel	B-Operating_System
threads	B-Operating_System
)	O
can	O
be	O
problematic	O
.	O
</s>
<s>
If	O
a	O
user	O
thread	B-Operating_System
or	O
a	O
fiber	O
performs	O
a	O
system	O
call	O
that	O
blocks	O
,	O
the	O
other	O
user	O
threads	B-Operating_System
and	O
fibers	B-Operating_System
in	O
the	O
process	B-Operating_System
are	O
unable	O
to	O
run	O
until	O
the	O
system	O
call	O
returns	O
.	O
</s>
<s>
In	O
the	O
intervening	O
period	O
,	O
the	O
entire	O
process	B-Operating_System
is	O
"	O
blocked	O
"	O
by	O
the	O
kernel	B-Operating_System
and	O
cannot	O
run	O
,	O
which	O
starves	O
other	O
user	O
threads	B-Operating_System
and	O
fibers	B-Operating_System
in	O
the	O
same	O
process	B-Operating_System
from	O
executing	O
.	O
</s>
<s>
A	O
common	O
solution	O
to	O
this	O
problem	O
(	O
used	O
,	O
in	O
particular	O
,	O
by	O
many	O
green	B-Operating_System
threads	I-Operating_System
implementations	O
)	O
is	O
providing	O
an	O
I/O	O
API	B-Application
that	O
implements	O
an	O
interface	O
that	O
blocks	O
the	O
calling	O
thread	B-Operating_System
,	O
rather	O
than	O
the	O
entire	O
process	B-Operating_System
,	O
by	O
using	O
non-blocking	B-Architecture
I/O	I-Architecture
internally	O
,	O
and	O
scheduling	O
another	O
user	O
thread	B-Operating_System
or	O
fiber	O
while	O
the	O
I/O	O
operation	O
is	O
in	O
progress	O
.	O
</s>
<s>
Alternatively	O
,	O
the	O
program	B-Application
can	O
be	O
written	O
to	O
avoid	O
the	O
use	O
of	O
synchronous	B-Architecture
I/O	I-Architecture
or	O
other	O
blocking	O
system	O
calls	O
(	O
in	O
particular	O
,	O
using	O
non-blocking	B-Architecture
I/O	I-Architecture
,	O
including	O
lambda	O
continuations	O
and/or	O
async/await	O
primitives	O
)	O
.	O
</s>
<s>
Fibers	B-Operating_System
are	O
an	O
even	O
lighter	O
unit	O
of	O
scheduling	O
which	O
are	O
cooperatively	B-Operating_System
scheduled	I-Operating_System
:	O
a	O
running	O
fiber	O
must	O
explicitly	O
"	O
yield	B-Language
"	O
to	O
allow	O
another	O
fiber	O
to	O
run	O
,	O
which	O
makes	O
their	O
implementation	O
much	O
easier	O
than	O
kernel	B-Operating_System
or	O
user	O
threads	B-Operating_System
.	O
</s>
<s>
A	O
fiber	O
can	O
be	O
scheduled	O
to	O
run	O
in	O
any	O
thread	B-Operating_System
in	O
the	O
same	O
process	B-Operating_System
.	O
</s>
<s>
This	O
permits	O
applications	O
to	O
gain	O
performance	O
improvements	O
by	O
managing	O
scheduling	O
themselves	O
,	O
instead	O
of	O
relying	O
on	O
the	O
kernel	B-Operating_System
scheduler	O
(	O
which	O
may	O
not	O
be	O
tuned	O
for	O
the	O
application	O
)	O
.	O
</s>
<s>
Parallel	B-Operating_System
programming	I-Operating_System
environments	O
such	O
as	O
OpenMP	B-Application
sometimes	O
implement	O
their	O
tasks	O
through	O
fibers	B-Operating_System
.	O
</s>
<s>
Closely	O
related	O
to	O
fibers	B-Operating_System
are	O
coroutines	B-Architecture
,	O
with	O
the	O
distinction	O
being	O
that	O
coroutines	B-Architecture
are	O
a	O
language-level	O
construct	O
,	O
while	O
fibers	B-Operating_System
are	O
a	O
system-level	O
construct	O
.	O
</s>
<s>
Threads	B-Operating_System
differ	O
from	O
traditional	O
multitasking	B-Operating_System
operating-system	O
processes	B-Operating_System
in	O
several	O
ways	O
:	O
</s>
<s>
Systems	O
such	O
as	O
Windows	B-Device
NT	I-Device
and	O
OS/2	B-Application
are	O
said	O
to	O
have	O
cheap	O
threads	B-Operating_System
and	O
expensive	O
processes	B-Operating_System
;	O
in	O
other	O
operating	B-General_Concept
systems	I-General_Concept
there	O
is	O
not	O
so	O
great	O
a	O
difference	O
except	O
in	O
the	O
cost	O
of	O
an	O
address-space	B-Operating_System
switch	I-Operating_System
,	O
which	O
on	O
some	O
architectures	O
(	O
notably	O
x86	B-Operating_System
)	O
results	O
in	O
a	O
translation	B-Architecture
lookaside	I-Architecture
buffer	I-Architecture
(	O
TLB	O
)	O
flush	O
.	O
</s>
<s>
Advantages	O
and	O
disadvantages	O
of	O
threads	B-Operating_System
vs	O
processes	B-Operating_System
include	O
:	O
</s>
<s>
Lower	O
resource	O
consumption	O
of	O
threads	B-Operating_System
:	O
using	O
threads	B-Operating_System
,	O
an	O
application	O
can	O
operate	O
using	O
fewer	O
resources	B-General_Concept
than	O
it	O
would	O
need	O
when	O
using	O
multiple	O
processes	B-Operating_System
.	O
</s>
<s>
Simplified	O
sharing	O
and	O
communication	O
of	O
threads	B-Operating_System
:	O
unlike	O
processes	B-Operating_System
,	O
which	O
require	O
a	O
message	B-Architecture
passing	I-Architecture
or	O
shared	B-Operating_System
memory	I-Operating_System
mechanism	O
to	O
perform	O
inter-process	B-Operating_System
communication	I-Operating_System
(	O
IPC	B-Operating_System
)	O
,	O
threads	B-Operating_System
can	O
communicate	O
through	O
data	O
,	O
code	O
and	O
files	O
they	O
already	O
share	O
.	O
</s>
<s>
Thread	B-Operating_System
crashes	O
a	O
process	B-Operating_System
:	O
due	O
to	O
threads	B-Operating_System
sharing	O
the	O
same	O
address	B-General_Concept
space	I-General_Concept
,	O
an	O
illegal	O
operation	O
performed	O
by	O
a	O
thread	B-Operating_System
can	O
crash	O
the	O
entire	O
process	B-Operating_System
;	O
therefore	O
,	O
one	O
misbehaving	O
thread	B-Operating_System
can	O
disrupt	O
the	O
processing	O
of	O
all	O
the	O
other	O
threads	B-Operating_System
in	O
the	O
application	O
.	O
</s>
<s>
Operating	B-General_Concept
systems	I-General_Concept
schedule	O
threads	B-Operating_System
either	O
preemptively	B-Operating_System
or	O
cooperatively	B-Operating_System
.	O
</s>
<s>
Multi-user	O
operating	B-General_Concept
systems	I-General_Concept
generally	O
favor	O
preemptive	B-Operating_System
multithreading	I-Operating_System
for	O
its	O
finer-grained	O
control	O
over	O
execution	B-General_Concept
time	O
via	O
context	B-Operating_System
switching	I-Operating_System
.	O
</s>
<s>
However	O
,	O
preemptive	B-Operating_System
scheduling	I-Operating_System
may	O
context-switch	O
threads	B-Operating_System
at	O
moments	O
unanticipated	O
by	O
programmers	B-Application
,	O
thus	O
causing	O
lock	B-Operating_System
convoy	I-Operating_System
,	O
priority	B-Operating_System
inversion	I-Operating_System
,	O
or	O
other	O
side-effects	O
.	O
</s>
<s>
In	O
contrast	O
,	O
cooperative	B-Operating_System
multithreading	I-Operating_System
relies	O
on	O
threads	B-Operating_System
to	O
relinquish	O
control	O
of	O
execution	B-General_Concept
,	O
thus	O
ensuring	O
that	O
threads	B-Operating_System
run	O
to	O
completion	O
.	O
</s>
<s>
This	O
can	O
cause	O
problems	O
if	O
a	O
cooperatively	B-Operating_System
multitasked	O
thread	B-Operating_System
blocks	O
by	O
waiting	O
on	O
a	O
resource	B-General_Concept
or	O
if	O
it	O
starves	O
other	O
threads	B-Operating_System
by	O
not	O
yielding	O
control	O
of	O
execution	B-General_Concept
during	O
intensive	O
computation	O
.	O
</s>
<s>
Until	O
the	O
early	O
2000s	O
,	O
most	O
desktop	O
computers	O
had	O
only	O
one	O
single-core	O
CPU	O
,	O
with	O
no	O
support	O
for	O
hardware	B-General_Concept
threads	I-General_Concept
,	O
although	O
threads	B-Operating_System
were	O
still	O
used	O
on	O
such	O
computers	O
because	O
switching	O
between	O
threads	B-Operating_System
was	O
generally	O
still	O
quicker	O
than	O
full-process	O
context	B-Operating_System
switches	I-Operating_System
.	O
</s>
<s>
In	O
2002	O
,	O
Intel	O
added	O
support	O
for	O
simultaneous	B-Operating_System
multithreading	I-Operating_System
to	O
the	O
Pentium	O
4	O
processor	O
,	O
under	O
the	O
name	O
hyper-threading	B-Operating_System
;	O
in	O
2005	O
,	O
they	O
introduced	O
the	O
dual-core	B-Architecture
Pentium	O
D	O
processor	O
and	O
AMD	O
introduced	O
the	O
dual-core	B-Architecture
Athlon	O
64	O
X2	O
processor	O
.	O
</s>
<s>
Systems	O
with	O
a	O
single	O
processor	O
generally	O
implement	O
multithreading	B-General_Concept
by	O
time	O
slicing	O
:	O
the	O
central	B-General_Concept
processing	I-General_Concept
unit	I-General_Concept
(	O
CPU	O
)	O
switches	O
between	O
different	O
software	B-Operating_System
threads	I-Operating_System
.	O
</s>
<s>
This	O
context	B-Operating_System
switching	I-Operating_System
usually	O
occurs	O
frequently	O
enough	O
that	O
users	O
perceive	O
the	O
threads	B-Operating_System
or	O
tasks	O
as	O
running	O
in	O
parallel	B-Operating_System
(	O
for	O
popular	O
server/desktop	O
operating	O
systems	O
,	O
maximum	O
time	O
slice	O
of	O
a	O
thread	B-Operating_System
,	O
when	O
other	O
threads	B-Operating_System
are	O
waiting	O
,	O
is	O
often	O
limited	O
to	O
100-200ms	O
)	O
.	O
</s>
<s>
On	O
a	O
multiprocessor	B-Operating_System
or	O
multi-core	B-Architecture
system	O
,	O
multiple	O
threads	B-Operating_System
can	O
execute	O
in	O
parallel	B-Operating_System
,	O
with	O
every	O
processor	O
or	O
core	O
executing	O
a	O
separate	O
thread	B-Operating_System
simultaneously	O
;	O
on	O
a	O
processor	O
or	O
core	O
with	O
hardware	B-General_Concept
threads	I-General_Concept
,	O
separate	O
software	B-Operating_System
threads	I-Operating_System
can	O
also	O
be	O
executed	O
concurrently	B-Architecture
by	O
separate	O
hardware	B-General_Concept
threads	I-General_Concept
.	O
</s>
<s>
Threads	B-Operating_System
created	O
by	O
the	O
user	O
in	O
a	O
1:1	O
correspondence	O
with	O
schedulable	O
entities	O
in	O
the	O
kernel	B-Operating_System
are	O
the	O
simplest	O
possible	O
threading	O
implementation	O
.	O
</s>
<s>
OS/2	B-Application
and	O
Win32	B-Library
used	O
this	O
approach	O
from	O
the	O
start	O
,	O
while	O
on	O
Linux	B-Application
the	O
GNU	B-Language
C	I-Language
Library	I-Language
implements	O
this	O
approach	O
(	O
via	O
the	O
NPTL	B-Application
or	O
older	O
LinuxThreads	B-Operating_System
)	O
.	O
</s>
<s>
This	O
approach	O
is	O
also	O
used	O
by	O
Solaris	B-Application
,	O
NetBSD	B-Device
,	O
FreeBSD	B-Operating_System
,	O
macOS	B-Application
,	O
and	O
iOS	B-Application
.	O
</s>
<s>
An	O
N:1	O
model	O
implies	O
that	O
all	O
application-level	O
threads	B-Operating_System
map	O
to	O
one	O
kernel-level	O
scheduled	O
entity	O
;	O
the	O
kernel	B-Operating_System
has	O
no	O
knowledge	O
of	O
the	O
application	O
threads	B-Operating_System
.	O
</s>
<s>
With	O
this	O
approach	O
,	O
context	B-Operating_System
switching	I-Operating_System
can	O
be	O
done	O
very	O
quickly	O
and	O
,	O
in	O
addition	O
,	O
it	O
can	O
be	O
implemented	O
even	O
on	O
simple	O
kernels	B-Operating_System
which	O
do	O
not	O
support	O
threading	O
.	O
</s>
<s>
One	O
of	O
the	O
major	O
drawbacks	O
,	O
however	O
,	O
is	O
that	O
it	O
cannot	O
benefit	O
from	O
the	O
hardware	O
acceleration	O
on	O
multithreaded	B-General_Concept
processors	O
or	O
multi-processor	B-Operating_System
computers	O
:	O
there	O
is	O
never	O
more	O
than	O
one	O
thread	B-Operating_System
being	O
scheduled	O
at	O
the	O
same	O
time	O
.	O
</s>
<s>
For	O
example	O
:	O
If	O
one	O
of	O
the	O
threads	B-Operating_System
needs	O
to	O
execute	O
an	O
I/O	O
request	O
,	O
the	O
whole	O
process	B-Operating_System
is	O
blocked	O
and	O
the	O
threading	O
advantage	O
cannot	O
be	O
used	O
.	O
</s>
<s>
The	O
GNU	B-Application
Portable	I-Application
Threads	I-Application
uses	O
User-level	B-Operating_System
threading	O
,	O
as	O
does	O
State	B-Application
Threads	I-Application
.	O
</s>
<s>
M:N	O
maps	O
some	O
number	O
of	O
application	O
threads	B-Operating_System
onto	O
some	O
number	O
of	O
kernel	B-Operating_System
entities	O
,	O
or	O
"	O
virtual	O
processors.	O
"	O
</s>
<s>
This	O
is	O
a	O
compromise	O
between	O
kernel-level	O
(	O
"	O
1:1	O
"	O
)	O
and	O
user-level	B-Operating_System
(	O
"	O
N:1	O
"	O
)	O
threading	O
.	O
</s>
<s>
In	O
general	O
,	O
"	O
M:N	O
"	O
threading	O
systems	O
are	O
more	O
complex	O
to	O
implement	O
than	O
either	O
kernel	B-Operating_System
or	O
user	O
threads	B-Operating_System
,	O
because	O
changes	O
to	O
both	O
kernel	B-Operating_System
and	O
user-space	B-Operating_System
code	O
are	O
required	O
.	O
</s>
<s>
In	O
the	O
M:N	O
implementation	O
,	O
the	O
threading	O
library	O
is	O
responsible	O
for	O
scheduling	O
user	O
threads	B-Operating_System
on	O
the	O
available	O
schedulable	O
entities	O
;	O
this	O
makes	O
context	B-Operating_System
switching	I-Operating_System
of	O
threads	B-Operating_System
very	O
fast	O
,	O
as	O
it	O
avoids	O
system	O
calls	O
.	O
</s>
<s>
However	O
,	O
this	O
increases	O
complexity	O
and	O
the	O
likelihood	O
of	O
priority	B-Operating_System
inversion	I-Operating_System
,	O
as	O
well	O
as	O
suboptimal	O
scheduling	O
without	O
extensive	O
(	O
and	O
expensive	O
)	O
coordination	O
between	O
the	O
userland	O
scheduler	O
and	O
the	O
kernel	B-Operating_System
scheduler	O
.	O
</s>
<s>
Marcel	O
from	O
the	O
PM2	B-Application
project	O
.	O
</s>
<s>
The	B-Application
Glasgow	I-Application
Haskell	I-Application
Compiler	I-Application
(	O
GHC	O
)	O
for	O
the	O
language	O
Haskell	B-Language
uses	O
lightweight	B-Operating_System
threads	I-Operating_System
which	O
are	O
scheduled	O
on	O
operating	B-General_Concept
system	I-General_Concept
threads	B-Operating_System
.	O
</s>
<s>
SunOS	B-Operating_System
4.x	O
implemented	O
light-weight	B-Operating_System
processes	I-Operating_System
or	O
LWPs	O
.	O
</s>
<s>
NetBSD	B-Device
2.x	O
+	O
,	O
and	O
DragonFly	B-Application
BSD	I-Application
implement	O
LWPs	O
as	O
kernel	B-Operating_System
threads	B-Operating_System
(	O
1:1	O
model	O
)	O
.	O
</s>
<s>
SunOS	B-Operating_System
5.2	O
through	O
SunOS	B-Operating_System
5.8	O
as	O
well	O
as	O
NetBSD	B-Device
2	O
to	O
NetBSD	B-Device
4	O
implemented	O
a	O
two	O
level	O
model	O
,	O
multiplexing	O
one	O
or	O
more	O
user	O
level	O
threads	B-Operating_System
on	O
each	O
kernel	B-Operating_System
thread	B-Operating_System
(	O
M:N	O
model	O
)	O
.	O
</s>
<s>
SunOS	B-Operating_System
5.9	O
and	O
later	O
,	O
as	O
well	O
as	O
NetBSD	B-Device
5	O
eliminated	O
user	O
threads	B-Operating_System
support	O
,	O
returning	O
to	O
a	O
1:1	O
model	O
.	O
</s>
<s>
FreeBSD	B-Operating_System
5	O
implemented	O
M:N	O
model	O
.	O
</s>
<s>
FreeBSD	B-Operating_System
6	O
supported	O
both	O
1:1	O
and	O
M:N	O
,	O
users	O
could	O
choose	O
which	O
one	O
should	O
be	O
used	O
with	O
a	O
given	O
program	B-Application
using	O
/etc/libmap.conf	O
.	O
</s>
<s>
Starting	O
with	O
FreeBSD	B-Operating_System
7	O
,	O
the	O
1:1	O
became	O
the	O
default	O
.	O
</s>
<s>
FreeBSD	B-Operating_System
8	O
no	O
longer	O
supports	O
the	O
M:N	O
model	O
.	O
</s>
<s>
In	O
computer	B-General_Concept
programming	I-General_Concept
,	O
single-threading	B-Operating_System
is	O
the	O
processing	O
of	O
one	O
command	B-Application
at	O
a	O
time	O
.	O
</s>
<s>
In	O
the	O
formal	O
analysis	O
of	O
the	O
variables	O
 '	O
semantics	B-Application
and	O
process	B-Operating_System
state	B-Application
,	O
the	O
term	O
single	B-Operating_System
threading	I-Operating_System
can	O
be	O
used	O
differently	O
to	O
mean	O
"	O
backtracking	O
within	O
a	O
single	B-Operating_System
thread	I-Operating_System
"	O
,	O
which	O
is	O
common	O
in	O
the	O
functional	B-Language
programming	I-Language
community	O
.	O
</s>
<s>
Multithreading	B-General_Concept
is	O
mainly	O
found	O
in	O
multitasking	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
.	O
</s>
<s>
Multithreading	B-General_Concept
is	O
a	O
widespread	O
programming	O
and	O
execution	B-General_Concept
model	O
that	O
allows	O
multiple	O
threads	B-Operating_System
to	O
exist	O
within	O
the	O
context	O
of	O
one	O
process	B-Operating_System
.	O
</s>
<s>
These	O
threads	B-Operating_System
share	O
the	O
process	B-Operating_System
's	O
resources	B-General_Concept
,	O
but	O
are	O
able	O
to	O
execute	O
independently	O
.	O
</s>
<s>
The	O
threaded	O
programming	O
model	O
provides	O
developers	B-Application
with	O
a	O
useful	O
abstraction	O
of	O
concurrent	B-Operating_System
execution	B-General_Concept
.	O
</s>
<s>
Multithreading	B-General_Concept
can	O
also	O
be	O
applied	O
to	O
one	O
process	B-Operating_System
to	O
enable	O
parallel	B-Operating_System
execution	I-Operating_System
on	O
a	O
multiprocessing	B-Operating_System
system	O
.	O
</s>
<s>
Multithreading	B-General_Concept
libraries	O
tend	O
to	O
provide	O
a	O
function	O
call	O
to	O
create	O
a	O
new	O
thread	B-Operating_System
,	O
which	O
takes	O
a	O
function	O
as	O
a	O
parameter	O
.	O
</s>
<s>
A	O
concurrent	B-Operating_System
thread	B-Operating_System
is	O
then	O
created	O
which	O
starts	O
running	O
the	O
passed	O
function	O
and	O
ends	O
when	O
the	O
function	O
returns	O
.	O
</s>
<s>
The	O
thread	B-Operating_System
libraries	O
also	O
offer	O
data	O
synchronization	O
functions	O
.	O
</s>
<s>
Threads	B-Operating_System
in	O
the	O
same	O
process	B-Operating_System
share	O
the	O
same	O
address	B-General_Concept
space	I-General_Concept
.	O
</s>
<s>
This	O
allows	O
concurrently	B-Architecture
running	O
code	O
to	O
couple	B-Application
tightly	O
and	O
conveniently	O
exchange	O
data	O
without	O
the	O
overhead	O
or	O
complexity	O
of	O
an	O
IPC	B-Operating_System
.	O
</s>
<s>
When	O
shared	O
between	O
threads	B-Operating_System
,	O
however	O
,	O
even	O
simple	O
data	O
structures	O
become	O
prone	O
to	O
race	B-Operating_System
conditions	I-Operating_System
if	O
they	O
require	O
more	O
than	O
one	O
CPU	O
instruction	O
to	O
update	O
:	O
two	O
threads	B-Operating_System
may	O
end	O
up	O
attempting	O
to	O
update	O
the	O
data	O
structure	O
at	O
the	O
same	O
time	O
and	O
find	O
it	O
unexpectedly	O
changing	O
underfoot	O
.	O
</s>
<s>
Bugs	O
caused	O
by	O
race	B-Operating_System
conditions	I-Operating_System
can	O
be	O
very	O
difficult	O
to	O
reproduce	O
and	O
isolate	O
.	O
</s>
<s>
To	O
prevent	O
this	O
,	O
threading	O
application	B-Application
programming	I-Application
interfaces	I-Application
(	O
APIs	B-Application
)	O
offer	O
synchronization	O
primitives	O
such	O
as	O
mutexes	B-Operating_System
to	O
lock	B-Operating_System
data	O
structures	O
against	O
concurrent	B-Operating_System
access	O
.	O
</s>
<s>
On	O
uniprocessor	O
systems	O
,	O
a	O
thread	B-Operating_System
running	O
into	O
a	O
locked	O
mutex	B-Operating_System
must	O
sleep	O
and	O
hence	O
trigger	O
a	O
context	B-Operating_System
switch	I-Operating_System
.	O
</s>
<s>
On	O
multi-processor	B-Operating_System
systems	O
,	O
the	O
thread	B-Operating_System
may	O
instead	O
poll	O
the	O
mutex	B-Operating_System
in	O
a	O
spinlock	B-Operating_System
.	O
</s>
<s>
Both	O
of	O
these	O
may	O
sap	O
performance	O
and	O
force	O
processors	O
in	O
symmetric	B-Operating_System
multiprocessing	I-Operating_System
(	O
SMP	O
)	O
systems	O
to	O
contend	O
for	O
the	O
memory	B-General_Concept
bus	O
,	O
especially	O
if	O
the	O
granularity	O
of	O
the	O
locking	B-Operating_System
is	O
too	O
fine	O
.	O
</s>
<s>
Other	O
synchronization	O
APIs	B-Application
include	O
condition	O
variables	O
,	O
critical	B-Operating_System
sections	I-Operating_System
,	O
semaphores	B-Operating_System
,	O
and	O
monitors	O
.	O
</s>
<s>
A	O
popular	O
programming	O
pattern	O
involving	O
threads	B-Operating_System
is	O
that	O
of	O
thread	B-Operating_System
pools	I-Operating_System
where	O
a	O
set	O
number	O
of	O
threads	B-Operating_System
are	O
created	O
at	O
startup	O
that	O
then	O
wait	O
for	O
a	O
task	O
to	O
be	O
assigned	O
.	O
</s>
<s>
This	O
avoids	O
the	O
relatively	O
expensive	O
thread	B-Operating_System
creation	O
and	O
destruction	O
functions	O
for	O
every	O
task	O
performed	O
and	O
takes	O
thread	B-Operating_System
management	I-Operating_System
out	O
of	O
the	O
application	B-Application
developer	I-Application
's	O
hand	O
and	O
leaves	O
it	O
to	O
a	O
library	O
or	O
the	O
operating	B-General_Concept
system	I-General_Concept
that	O
is	O
better	O
suited	O
to	O
optimize	O
thread	B-Operating_System
management	I-Operating_System
.	O
</s>
<s>
Multithreaded	B-General_Concept
applications	O
have	O
the	O
following	O
advantages	O
vs	O
single-threaded	B-Operating_System
ones	O
:	O
</s>
<s>
Responsiveness	O
:	O
multithreading	B-General_Concept
can	O
allow	O
an	O
application	O
to	O
remain	O
responsive	O
to	O
input	O
.	O
</s>
<s>
In	O
a	O
one-thread	O
program	B-Application
,	O
if	O
the	O
main	O
execution	B-General_Concept
thread	B-Operating_System
blocks	O
on	O
a	O
long-running	O
task	O
,	O
the	O
entire	O
application	O
can	O
appear	O
to	O
freeze	O
.	O
</s>
<s>
By	O
moving	O
such	O
long-running	O
tasks	O
to	O
a	O
worker	O
thread	B-Operating_System
that	O
runs	O
concurrently	B-Architecture
with	O
the	O
main	O
execution	B-General_Concept
thread	B-Operating_System
,	O
it	O
is	O
possible	O
for	O
the	O
application	O
to	O
remain	O
responsive	O
to	O
user	O
input	O
while	O
executing	O
tasks	O
in	O
the	O
background	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
in	O
most	O
cases	O
multithreading	B-General_Concept
is	O
not	O
the	O
only	O
way	O
to	O
keep	O
a	O
program	B-Application
responsive	O
,	O
with	O
non-blocking	B-Architecture
I/O	I-Architecture
and/or	O
Unix	B-General_Concept
signals	I-General_Concept
being	O
available	O
for	O
obtaining	O
similar	O
results	O
.	O
</s>
<s>
Parallelization	B-Operating_System
:	O
applications	O
looking	O
to	O
use	O
multicore	B-Architecture
or	O
multi-CPU	O
systems	O
can	O
use	O
multithreading	B-General_Concept
to	O
split	O
data	O
and	O
tasks	O
into	O
parallel	B-Operating_System
subtasks	O
and	O
let	O
the	O
underlying	O
architecture	O
manage	O
how	O
the	O
threads	B-Operating_System
run	O
,	O
either	O
concurrently	B-Architecture
on	O
one	O
core	O
or	O
in	O
parallel	B-Operating_System
on	O
multiple	O
cores	O
.	O
</s>
<s>
GPU	O
computing	O
environments	O
like	O
CUDA	B-Architecture
and	O
OpenCL	B-Application
use	O
the	O
multithreading	B-General_Concept
model	O
where	O
dozens	O
to	O
hundreds	O
of	O
threads	B-Operating_System
run	O
in	O
parallel	B-Operating_System
across	I-Operating_System
data	I-Operating_System
on	O
a	O
large	B-General_Concept
number	I-General_Concept
of	I-General_Concept
cores	I-General_Concept
.	O
</s>
<s>
This	O
,	O
in	O
turn	O
,	O
enables	O
better	O
system	O
utilization	O
,	O
and	O
(	O
provided	O
that	O
synchronization	O
costs	O
do	O
n't	O
eat	O
the	O
benefits	O
up	O
)	O
,	O
can	O
provide	O
faster	O
program	B-Application
execution	B-General_Concept
.	O
</s>
<s>
Multithreaded	B-General_Concept
applications	O
have	O
the	O
following	O
drawbacks	O
:	O
</s>
<s>
Synchronization	O
complexity	O
and	O
related	O
bugs	O
:	O
when	O
using	O
shared	O
resources	B-General_Concept
typical	O
for	O
threaded	O
programs	O
,	O
the	O
programmer	B-Application
must	O
be	O
careful	O
to	O
avoid	O
race	B-Operating_System
conditions	I-Operating_System
and	O
other	O
non-intuitive	O
behaviors	O
.	O
</s>
<s>
In	O
order	O
for	O
data	O
to	O
be	O
correctly	O
manipulated	O
,	O
threads	B-Operating_System
will	O
often	O
need	O
to	O
rendezvous	O
in	O
time	O
in	O
order	O
to	O
process	B-Operating_System
the	O
data	O
in	O
the	O
correct	O
order	O
.	O
</s>
<s>
Threads	B-Operating_System
may	O
also	O
require	O
mutually	B-Operating_System
exclusive	I-Operating_System
operations	O
(	O
often	O
implemented	O
using	O
mutexes	B-Operating_System
)	O
to	O
prevent	O
common	O
data	O
from	O
being	O
read	O
or	O
overwritten	O
in	O
one	O
thread	B-Operating_System
while	O
being	O
modified	O
by	O
another	O
.	O
</s>
<s>
Careless	O
use	O
of	O
such	O
primitives	O
can	O
lead	O
to	O
deadlocks	B-Operating_System
,	O
livelocks	O
or	O
races	B-Operating_System
over	O
resources	B-General_Concept
.	O
</s>
<s>
As	O
Edward	O
A	O
.	O
Lee	O
has	O
written	O
:	O
"	O
Although	O
threads	B-Operating_System
seem	O
to	O
be	O
a	O
small	O
step	O
from	O
sequential	O
computation	O
,	O
in	O
fact	O
,	O
they	O
represent	O
a	O
huge	O
step	O
.	O
</s>
<s>
Threads	B-Operating_System
,	O
as	O
a	O
model	O
of	O
computation	O
,	O
are	O
wildly	O
non-deterministic	O
,	O
and	O
the	O
job	O
of	O
the	O
programmer	B-Application
becomes	O
one	O
of	O
pruning	O
that	O
nondeterminism.	O
"	O
</s>
<s>
In	O
general	O
,	O
multithreaded	B-General_Concept
programs	O
are	O
non-deterministic	O
,	O
and	O
as	O
a	O
result	O
,	O
are	O
untestable	O
.	O
</s>
<s>
In	O
other	O
words	O
,	O
a	O
multithreaded	B-General_Concept
program	B-Application
can	O
easily	O
have	O
bugs	O
which	O
never	O
manifest	O
on	O
a	O
test	O
system	O
,	O
manifesting	O
only	O
in	O
production	O
.	O
</s>
<s>
This	O
can	O
be	O
alleviated	O
by	O
restricting	O
inter-thread	B-Operating_System
communications	I-Operating_System
to	O
certain	O
well-defined	O
patterns	O
(	O
such	O
as	O
message-passing	B-Architecture
)	O
.	O
</s>
<s>
As	O
thread	B-Operating_System
context	B-Operating_System
switch	I-Operating_System
on	O
modern	O
CPUs	O
can	O
cost	O
up	O
to	O
1	O
million	O
CPU	O
cycles	O
,	O
it	O
makes	O
writing	O
efficient	O
multithreading	B-General_Concept
programs	O
difficult	O
.	O
</s>
<s>
In	O
particular	O
,	O
special	O
attention	O
has	O
to	O
be	O
paid	O
to	O
avoid	O
inter-thread	O
synchronization	O
from	O
being	O
too	O
frequent	O
.	O
</s>
<s>
IBM	O
PL/I	B-Language
( F	O
)	O
included	O
support	O
for	O
multithreading	B-General_Concept
(	O
called	O
multitasking	B-Operating_System
)	O
as	O
early	O
as	O
in	O
the	O
late	O
1960s	O
,	O
and	O
this	O
was	O
continued	O
in	O
the	O
Optimizing	O
Compiler	O
and	O
later	O
versions	O
.	O
</s>
<s>
The	O
IBM	O
Enterprise	O
PL/I	B-Language
compiler	O
introduced	O
a	O
new	O
model	O
"	O
thread	B-Operating_System
"	O
API	B-Application
.	O
</s>
<s>
Neither	O
version	O
was	O
part	O
of	O
the	O
PL/I	B-Language
standard	O
.	O
</s>
<s>
Many	O
implementations	O
of	O
C	B-Language
and	O
C++	B-Language
support	O
threading	O
,	O
and	O
provide	O
access	O
to	O
the	O
native	O
threading	O
APIs	B-Application
of	O
the	O
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
A	O
standardized	O
interface	O
for	O
thread	B-Operating_System
implementation	O
is	O
POSIX	B-Operating_System
Threads	I-Operating_System
(	O
Pthreads	B-Operating_System
)	O
,	O
which	O
is	O
a	O
set	O
of	O
C-function	O
library	O
calls	O
.	O
</s>
<s>
OS	O
vendors	O
are	O
free	O
to	O
implement	O
the	O
interface	O
as	O
desired	O
,	O
but	O
the	O
application	B-Application
developer	I-Application
should	O
be	O
able	O
to	O
use	O
the	O
same	O
interface	O
across	O
multiple	B-Operating_System
platforms	I-Operating_System
.	O
</s>
<s>
Most	O
Unix	B-Application
platforms	O
,	O
including	O
Linux	B-Application
,	O
support	O
Pthreads	B-Operating_System
.	O
</s>
<s>
Microsoft	O
Windows	O
has	O
its	O
own	O
set	O
of	O
thread	B-Operating_System
functions	O
in	O
the	O
process.h	B-Language
interface	O
for	O
multithreading	B-General_Concept
,	O
like	O
beginthread	B-Operating_System
.	O
</s>
<s>
Some	O
higher	B-Language
level	I-Language
(	O
and	O
usually	O
cross-platform	B-Operating_System
)	O
programming	O
languages	O
,	O
such	O
as	O
Java	B-Language
,	O
Python	B-Language
,	O
and	O
.NET	B-Application
Framework	I-Application
languages	O
,	O
expose	O
threading	O
to	O
developers	B-Application
while	O
abstracting	O
the	O
platform	O
specific	O
differences	O
in	O
threading	O
implementations	O
in	O
the	O
runtime	O
.	O
</s>
<s>
Several	O
other	O
programming	O
languages	O
and	O
language	O
extensions	O
also	O
try	O
to	O
abstract	O
the	O
concept	O
of	O
concurrency	B-Architecture
and	O
threading	O
from	O
the	O
developer	B-Application
fully	O
(	O
Cilk	B-Language
,	O
OpenMP	B-Application
,	O
Message	B-Application
Passing	I-Application
Interface	I-Application
(	O
MPI	O
)	O
)	O
.	O
</s>
<s>
Some	O
languages	O
are	O
designed	O
for	O
sequential	O
parallelism	B-Operating_System
instead	O
(	O
especially	O
using	O
GPUs	O
)	O
,	O
without	O
requiring	O
concurrency	B-Architecture
or	O
threads	B-Operating_System
(	O
Ateji	B-Language
PX	I-Language
,	O
CUDA	B-Architecture
)	O
.	O
</s>
<s>
A	O
few	O
interpreted	O
programming	O
languages	O
have	O
implementations	O
(	O
e.g.	O
,	O
Ruby	B-Language
MRI	I-Language
for	O
Ruby	O
,	O
CPython	B-Language
for	O
Python	B-Language
)	O
which	O
support	O
threading	O
and	O
concurrency	B-Architecture
but	O
not	O
parallel	B-Operating_System
execution	I-Operating_System
of	O
threads	B-Operating_System
,	O
due	O
to	O
a	O
global	B-Operating_System
interpreter	I-Operating_System
lock	I-Operating_System
(	O
GIL	O
)	O
.	O
</s>
<s>
The	O
GIL	O
is	O
a	O
mutual	B-Operating_System
exclusion	I-Operating_System
lock	B-Operating_System
held	O
by	O
the	O
interpreter	O
that	O
can	O
prevent	O
the	O
interpreter	O
from	O
simultaneously	O
interpreting	O
the	O
applications	O
code	O
on	O
two	O
or	O
more	O
threads	B-Operating_System
at	O
once	O
,	O
which	O
effectively	O
limits	O
the	O
parallelism	B-Operating_System
on	O
multiple	O
core	O
systems	O
.	O
</s>
<s>
This	O
limits	O
performance	O
mostly	O
for	O
processor-bound	O
threads	B-Operating_System
,	O
which	O
require	O
the	O
processor	O
,	O
and	O
not	O
much	O
for	O
I/O	O
-bound	O
or	O
network-bound	O
ones	O
.	O
</s>
<s>
Other	O
implementations	O
of	O
interpreted	O
programming	O
languages	O
,	O
such	O
as	O
Tcl	B-Operating_System
using	O
the	O
Thread	B-Operating_System
extension	O
,	O
avoid	O
the	O
GIL	O
limit	O
by	O
using	O
an	O
Apartment	O
model	O
where	O
data	O
and	O
code	O
must	O
be	O
explicitly	O
"	O
shared	O
"	O
between	O
threads	B-Operating_System
.	O
</s>
<s>
In	O
Tcl	B-Operating_System
each	O
thread	B-Operating_System
has	O
one	O
or	O
more	O
interpreters	O
.	O
</s>
<s>
In	O
programming	O
models	O
such	O
as	O
CUDA	B-Architecture
designed	O
for	O
data	B-Operating_System
parallel	I-Operating_System
computation	I-Operating_System
,	O
an	O
array	O
of	O
threads	B-Operating_System
run	O
the	B-Operating_System
same	I-Operating_System
code	I-Operating_System
in	O
parallel	B-Operating_System
using	O
only	O
its	O
ID	O
to	O
find	O
its	O
data	O
in	O
memory	B-General_Concept
.	O
</s>
<s>
In	O
essence	O
,	O
the	O
application	O
must	O
be	O
designed	O
so	O
that	O
each	O
thread	B-Operating_System
performs	O
the	O
same	O
operation	O
on	O
different	O
segments	O
of	O
memory	B-General_Concept
so	O
that	O
they	O
can	O
operate	O
in	O
parallel	B-Operating_System
and	O
use	O
the	O
GPU	O
architecture	O
.	O
</s>
<s>
Hardware	O
description	O
languages	O
such	O
as	O
Verilog	B-Language
have	O
a	O
different	O
threading	O
model	O
that	O
supports	O
extremely	O
large	O
numbers	O
of	O
threads	B-Operating_System
(	O
for	O
modeling	O
hardware	O
)	O
.	O
</s>
