<s>
In	O
computer	B-General_Concept
operating	I-General_Concept
systems	I-General_Concept
,	O
a	O
light-weight	B-Operating_System
process	I-Operating_System
(	O
LWP	O
)	O
is	O
a	O
means	O
of	O
achieving	O
multitasking	B-Operating_System
.	O
</s>
<s>
In	O
the	O
traditional	O
meaning	O
of	O
the	O
term	O
,	O
as	O
used	O
in	O
Unix	B-Operating_System
System	I-Operating_System
V	I-Operating_System
and	O
Solaris	B-Application
,	O
a	O
LWP	O
runs	O
in	O
user	B-Operating_System
space	I-Operating_System
on	O
top	O
of	O
a	O
single	O
kernel	B-Operating_System
thread	B-Operating_System
and	O
shares	O
its	O
address	B-General_Concept
space	I-General_Concept
and	O
system	O
resources	O
with	O
other	O
LWPs	O
within	O
the	O
same	O
process	B-Operating_System
.	O
</s>
<s>
Multiple	O
user-level	B-Operating_System
threads	B-Operating_System
,	O
managed	O
by	O
a	O
thread	B-Operating_System
library	O
,	O
can	O
be	O
placed	O
on	O
top	O
of	O
one	O
or	O
many	O
LWPs	O
-	O
allowing	O
multitasking	B-Operating_System
to	O
be	O
done	O
at	O
the	O
user	O
level	O
,	O
which	O
can	O
have	O
some	O
performance	O
benefits	O
.	O
</s>
<s>
In	O
some	O
operating	B-General_Concept
systems	I-General_Concept
,	O
there	O
is	O
no	O
separate	O
LWP	O
layer	O
between	O
kernel	B-Operating_System
threads	B-Operating_System
and	O
user	O
threads	B-Operating_System
.	O
</s>
<s>
This	O
means	O
that	O
user	O
threads	B-Operating_System
are	O
implemented	O
directly	O
on	O
top	O
of	O
kernel	B-Operating_System
threads	B-Operating_System
.	O
</s>
<s>
In	O
those	O
contexts	O
,	O
the	O
term	O
"	O
light-weight	B-Operating_System
process	I-Operating_System
"	O
typically	O
refers	O
to	O
kernel	B-Operating_System
threads	B-Operating_System
and	O
the	O
term	O
"	O
threads	B-Operating_System
"	O
can	O
refer	O
to	O
user	O
threads	B-Operating_System
.	O
</s>
<s>
On	O
Linux	B-Operating_System
,	O
user	O
threads	B-Operating_System
are	O
implemented	O
by	O
allowing	O
certain	O
processes	O
to	O
share	O
resources	O
,	O
which	O
sometimes	O
leads	O
to	O
these	O
processes	O
to	O
be	O
called	O
"	O
light	O
weight	O
processes	O
"	O
.	O
</s>
<s>
Similarly	O
,	O
in	O
SunOS	B-Operating_System
version	O
4	O
onwards	O
(	O
prior	O
to	O
Solaris	B-Application
)	O
"	O
light	O
weight	O
process	B-Operating_System
"	O
referred	O
to	O
user	O
threads	B-Operating_System
.	O
</s>
<s>
Kernel	B-Operating_System
threads	B-Operating_System
are	O
handled	O
entirely	O
by	O
the	O
kernel	B-Operating_System
.	O
</s>
<s>
They	O
need	O
not	O
be	O
associated	O
with	O
a	O
process	B-Operating_System
;	O
a	O
kernel	B-Operating_System
can	O
create	O
them	O
whenever	O
it	O
needs	O
to	O
perform	O
a	O
particular	O
task	O
.	O
</s>
<s>
Kernel	B-Operating_System
threads	B-Operating_System
cannot	O
execute	O
in	O
user	B-Operating_System
mode	I-Operating_System
.	O
</s>
<s>
LWPs	O
(	O
in	O
systems	O
where	O
they	O
are	O
a	O
separate	O
layer	O
)	O
bind	O
to	O
kernel	B-Operating_System
threads	B-Operating_System
and	O
provide	O
a	O
user-level	B-Operating_System
context	O
.	O
</s>
<s>
This	O
includes	O
a	O
link	O
to	O
the	O
shared	O
resources	O
of	O
the	O
process	B-Operating_System
to	O
which	O
the	O
LWP	O
belongs	O
.	O
</s>
<s>
When	O
a	O
LWP	O
is	O
suspended	O
,	O
it	O
needs	O
to	O
store	O
its	O
user-level	B-Operating_System
registers	O
until	O
it	O
resumes	O
,	O
and	O
the	O
underlying	O
kernel	B-Operating_System
thread	B-Operating_System
must	O
also	O
store	O
its	O
own	O
kernel-level	O
registers	O
.	O
</s>
<s>
LWPs	O
are	O
slower	O
and	O
more	O
expensive	O
to	O
create	O
than	O
user	O
threads	B-Operating_System
.	O
</s>
<s>
Whenever	O
an	O
LWP	O
is	O
created	O
a	O
system	O
call	O
must	O
first	O
be	O
made	O
to	O
create	O
a	O
corresponding	O
kernel	B-Operating_System
thread	B-Operating_System
,	O
causing	O
a	O
switch	O
to	O
kernel	B-Operating_System
mode	O
.	O
</s>
<s>
These	O
mode	O
switches	O
would	O
typically	O
involve	O
copying	O
parameters	O
between	O
kernel	B-Operating_System
and	O
user	B-Operating_System
space	I-Operating_System
,	O
also	O
the	O
kernel	B-Operating_System
may	O
need	O
to	O
have	O
extra	O
steps	O
to	O
verify	O
the	O
parameters	O
to	O
check	O
for	O
invalid	O
behavior	O
.	O
</s>
<s>
A	O
context	B-Operating_System
switch	I-Operating_System
between	O
LWPs	O
means	O
that	O
the	O
LWP	O
that	O
is	O
being	O
pre-empted	O
has	O
to	O
save	O
its	O
registers	O
,	O
then	O
go	O
into	O
kernel	B-Operating_System
mode	O
for	O
the	O
kernel	B-Operating_System
thread	B-Operating_System
to	O
save	O
its	O
registers	O
,	O
and	O
the	O
LWP	O
that	O
is	O
being	O
scheduled	O
must	O
restore	O
the	O
kernel	B-Operating_System
and	O
user	O
registers	O
separately	O
also	O
.	O
</s>
<s>
For	O
this	O
reason	O
,	O
some	O
user	O
level	O
thread	B-Operating_System
libraries	O
allow	O
multiple	O
user	O
threads	B-Operating_System
to	O
be	O
implemented	O
on	O
top	O
of	O
LWPs	O
.	O
</s>
<s>
User	O
threads	B-Operating_System
can	O
be	O
created	O
,	O
destroyed	O
,	O
synchronized	O
and	O
switched	O
between	O
entirely	O
in	O
user	B-Operating_System
space	I-Operating_System
without	O
system	O
calls	O
and	O
switches	O
into	O
kernel	B-Operating_System
mode	O
.	O
</s>
<s>
This	O
provides	O
a	O
significant	O
performance	O
improvement	O
in	O
thread	B-Operating_System
creation	O
time	O
and	O
context	B-Operating_System
switches	I-Operating_System
.	O
</s>
<s>
However	O
,	O
there	O
are	O
difficulties	O
in	O
implementing	O
a	O
user	O
level	O
thread	B-Operating_System
scheduler	O
that	O
works	O
well	O
together	O
with	O
the	O
kernel	B-Operating_System
.	O
</s>
<s>
While	O
the	O
user	O
threading	O
library	O
will	O
schedule	O
user	O
threads	B-Operating_System
,	O
the	O
kernel	B-Operating_System
will	O
schedule	O
the	O
underlying	O
LWPs	O
.	O
</s>
<s>
Without	O
coordination	O
between	O
the	O
kernel	B-Operating_System
and	O
the	O
thread	B-Operating_System
library	O
the	O
kernel	B-Operating_System
can	O
make	O
sub-optimal	O
scheduling	O
decisions	O
.	O
</s>
<s>
Further	O
,	O
it	O
is	O
possible	O
for	O
cases	O
of	O
deadlock	O
to	O
occur	O
when	O
user	O
threads	B-Operating_System
distributed	O
over	O
several	O
LWPs	O
try	O
to	O
acquire	O
the	O
same	O
resources	O
that	O
are	O
used	O
by	O
another	O
user	O
thread	B-Operating_System
that	O
is	O
not	O
currently	O
running	O
.	O
</s>
<s>
This	O
is	O
a	O
method	O
for	O
the	O
kernel	B-Operating_System
and	O
the	O
thread	B-Operating_System
library	O
to	O
cooperate	O
.	O
</s>
<s>
The	O
kernel	B-Operating_System
notifies	O
the	O
thread	B-Operating_System
library	O
's	O
scheduler	O
about	O
certain	O
events	O
(	O
such	O
as	O
when	O
a	O
thread	B-Operating_System
is	O
about	O
to	O
block	O
)	O
and	O
the	O
thread	B-Operating_System
library	O
can	O
make	O
a	O
decision	O
on	O
what	O
action	O
to	O
take	O
.	O
</s>
<s>
The	O
notification	O
call	O
from	O
the	O
kernel	B-Operating_System
is	O
called	O
an	O
"	O
upcall	O
"	O
.	O
</s>
<s>
A	O
user	O
level	O
library	O
has	O
no	O
control	O
over	O
the	O
underlying	O
mechanism	O
,	O
it	O
only	O
receives	O
notifications	O
from	O
the	O
kernel	B-Operating_System
and	O
schedules	O
user	O
threads	B-Operating_System
onto	O
available	O
LWPs	O
,	O
not	O
processors	O
.	O
</s>
<s>
The	O
kernel	B-Operating_System
's	O
scheduler	O
then	O
decides	O
how	O
to	O
schedule	O
the	O
LWPs	O
onto	O
the	O
processors	O
.	O
</s>
<s>
This	O
means	O
that	O
LWPs	O
can	O
be	O
seen	O
by	O
the	O
thread	B-Operating_System
library	O
as	O
"	O
virtual	O
processors	O
"	O
.	O
</s>
<s>
Solaris	B-Application
has	O
implemented	O
a	O
separate	O
LWP	O
layer	O
since	O
version	O
2.2	O
.	O
</s>
<s>
Prior	O
to	O
version	O
9	O
,	O
Solaris	B-Application
allowed	O
a	O
many-to-many	O
mapping	O
between	O
LWPs	O
and	O
user	O
threads	B-Operating_System
.	O
</s>
<s>
However	O
,	O
this	O
was	O
retired	O
due	O
to	O
the	O
complexities	O
it	O
introduced	O
and	O
performance	O
improvements	O
to	O
the	O
kernel	B-Operating_System
scheduler	O
.	O
</s>
<s>
UNIX	B-Operating_System
System	I-Operating_System
V	I-Operating_System
and	O
its	O
modern	O
derivatives	O
IRIX	B-Operating_System
,	O
SCO	B-Operating_System
OpenServer	I-Operating_System
,	O
HP-UX	B-Application
and	O
IBM	B-Application
AIX	I-Application
allow	O
a	O
many-to-many	O
mapping	O
between	O
user	O
threads	B-Operating_System
and	O
LWPs	O
.	O
</s>
<s>
NetBSD	B-Device
5.0	O
introduced	O
a	O
new	O
,	O
scalable	O
1:1	O
threading	O
model	O
.	O
</s>
<s>
Each	O
user	O
thread	B-Operating_System
(	O
pthread	B-Operating_System
)	O
has	O
a	O
kernel	B-Operating_System
thread	B-Operating_System
called	O
a	O
light-weight	B-Operating_System
process	I-Operating_System
(	O
LWP	O
)	O
.	O
</s>
<s>
Inside	O
the	O
kernel	B-Operating_System
,	O
both	O
processes	O
and	O
threads	B-Operating_System
are	O
implemented	O
as	O
LWPs	O
,	O
and	O
are	O
served	O
the	O
same	O
by	O
the	O
scheduler	O
.	O
</s>
