>I am looking for some information on thread implementation in Linux.
>Specifically, does Linux support kernel level threads and lightweight
>processes? How are they implemented in relation to proc and u areas?
Any process (==thread of execution) is represented by task_struct.
Components of the virtual machine (memory context, descriptor table,
cwd+root, signals mask, etc.) are not located there, they are refered
from there (->mm, ->files, etc.). They can be shared. fork() creates
a new task_struct and populates it with pointers to copies of parents
components. clone() does the same, except that it you can tell it to
share some components with parent instead of copying them. Components
are reference-counted and exit() simply drops the reference (once the
refcount hits zero component is released). execve() builds new memory
contexts and signals, replaces pointers to these components in task_struct
of caller and drops the old ones.
There is no special notion of LWP (or thread, for that matter) - it's
simply not needed. Occam's razor and all such...
Relevant code is in kernel/fork.c, kernel/exit.c and fs/exec.c. RTFSource.
See also Plan 9 kernel for a related implementation, but keep in mind that
their treatment of memory context sharing is different - it's not the whole
memory context, it's memory context minus stack. IOW, processes that share
VM still have different contexts, they just happen to be almost identical
and are kept that way. Serious PITA for implementing coroutines... Otherwise
it's pretty close to our variant.
"You're one of those condescending Unix computer users!"
"Here's a nickel, kid. Get yourself a better computer" - Dilbert.