From: Kasper Dupont <kasperd@daimi.au.dk>
Subject: Re: User/Kernel Level Threads
Date: Thu, 26 Feb 2004 13:37:16 +0100 [thread overview]
Message-ID: <403DE87C.8384B493@daimi.au.dk> (raw)
In-Reply-To: cd6175dd.0402251311.1e83b415@posting.google.com
Anne wrote:
>
> Hello,
>
> I am confused about User level Thread /Kernel Level Threads. Could you
> please look at my following questions? Many thanks for your time
>
> 0- With Kernel Level thread, will the thread run on Kernel mode?
> that's what i have read, thread (user) code so can run on the kernel
> space, that's look very dangerous for me!
I think part of the confusion comes from the fact,
that the term "kernel threads" have been used about
two different things.
If a user mode program needs to use threads, they
can either be implemented in user mode or be a
feature offered by the kernel. The later have been
called kernel threads.
In Linux a handfull of the threads on the system
will be a part of the kernel handling various
kernel tasks, they are also called kernel threads,
but are something completely different from the
other kernel threads.
When a user mode program needs threads, the two
possibilities each have advantages and disadvantages.
Threads implemented in user mode have the advantage,
that they can be used even if the kernel doesn't
offer any threading. And thread switching can be
very fast. Except from those two points, threads
implemented in user mode have only disadvantages.
Threads implemented in user mode will not allow
more than one thread to run at any time even if
there are multiple CPUs. And even worse, if a thread
is blocked in a system call, that thread will still
occupy the process, so no other thread can execute
because the process is sleeping.
I have heard of hybrid user/kernel mode thread
implementations. But they have got to be very
complicated, and I doubt they have any major
advantages over an implementation 100% in kernel
mode.
The only real advantage of user mode threads when
kernel support for threads exists is the overhead
for switching between two threads. And that is only
significant if your program requires a lot of
switches between threads.
In Linux a lot of work have been done to keep the
overhead for switching between threads low. From
the kernel's point of view, the only thing special
about threaded programs compared to non-threaded
programs, is the fact that multiple user tasks
with same virtual memory space exists. And it will
use this knowledge to do
1) Lazy switching, which means only switch memory
map when it is strictly necesarry.
2) Give tasks with same virtual memory space as the
last used slightly higher priority when picking
the next task to be scheduled.
I have not heard about other systems that have made
the same effort to improve threading performance.
I haven't seen any comparisions between threads
using the Linux kernel, and threads implemented in
user space, so I don't know if there is any
significant difference in switching overhead.
--
Kasper Dupont -- der bruger for meget tid paa usenet.
For sending spam use mailto:aaarep@daimi.au.dk
/* Would you like fries with that? */
next prev parent reply other threads:[~2004-02-26 12:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-25 21:11 User/Kernel Level Threads Anne
2004-02-25 21:37 ` Alf P. Steinbach
2004-02-25 22:12 ` Nick Landsberg
2004-02-26 7:03 ` Nikola Milutinovic
2004-02-27 16:41 ` Peter da Silva
2004-02-26 12:37 ` Kasper Dupont [this message]
2004-03-03 17:30 ` John R
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox