Threads in Linux

Threads in Linux

Post by sanji » Fri, 22 Sep 2000 04:00:00



Hi net.wisdom:

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?

I'll appreciate any pointers to web sites or books.

Thanks in advance.

Sanjiv

 
 
 

Threads in Linux

Post by Andreas K?h?r » Sat, 23 Sep 2000 04:00:00




>Hi net.wisdom:

>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?

>I'll appreciate any pointers to web sites or books.

>Thanks in advance.

>Sanjiv

There are different definitions of "lightweight processes". GNU/Linux
does AFAIK not support LWPs as defined in e.g. Solaris. But if you
mean LWPs as begin equivalent to threads, then yes.

GNU/Linux Thread FAQ: <URL:http://www.linuxdoc.org/FAQ/Threads-FAQ/>

You're welcome.

/A

--
Andreas K?h?ri, <URL:http://hello.to/andkaha/>. Junk mail, no.
------------------------------------------------------------------------
What part of "GNU" did you not understand? <URL:http://www.gnu.org/>

 
 
 

Threads in Linux

Post by Mark Hah » Mon, 25 Sep 2000 04:00:00


Quote:>>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?

Linux (not this "GNU/Linux" silliness) does support kernel-level threads.
there are additionally several user-level threads packages.  Linux
kernel threads are, in fact, as lightweight as some user-level threads.

Linux doesn't have a "u area".  Linux's threads are based on the recognition
that tasks (from fork) are just threads that don't share much.  the
implementation is fairly easy to read; that's the best reference.

Quote:> There are different definitions of "lightweight processes". GNU/Linux
> does AFAIK not support LWPs as defined in e.g. Solaris. But if you

there certainly ARE user-level thread packages available for Linux.
 
 
 

Threads in Linux

Post by Andreas K?h?r » Tue, 26 Sep 2000 04:00:00




[cut]

Quote:>> There are different definitions of "lightweight processes". GNU/Linux
>> does AFAIK not support LWPs as defined in e.g. Solaris. But if you

>there certainly ARE user-level thread packages available for Linux.

Ah, there are indeed user-level thread packages in Linux. It says so
in the Thread FAQ [1]. I didn't say there weren't. Also, the FAQ links
to many thread packages.

/A

[1] <URL:http://www.linuxdoc.org/FAQ/Threads-FAQ/>

--
Andreas K?h?ri, <URL:http://hello.to/andkaha/>. Junk mail, no.
------------------------------------------------------------------------
What part of "GNU" did you not understand? <URL:http://www.gnu.org/>

 
 
 

Threads in Linux

Post by Alexander Vi » Tue, 26 Sep 2000 04:00:00




>Hi net.wisdom:

>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.