Difference between Userlevel Threads and Kernel level threads?

Hi there,
can somone please tell me the difference between user level threads and kernel level threads.

Also, if there is a difference in definition from OS to OS, can u also tell me what userlevel and kernel level threads do and how to they work in WINDOWS 2000 and Unix.

Who is Participating?
PhysicistmConnect With a Mentor Commented:
Well let's see the difference:

  User-level threads:
  * All thread management is done by the application.
  * The kernel is not aware of the existence of threads.
  * Thread switching does not require kernel mode privileges.
  * Scheduling is application specific.

  Kernel-level threads:
  * Windows/NT and OS/2 are examples of this approach.
  * Kernel maintains context information for the process and the threads.
  * Switching between threads requires the kernel.

Now these definitions should of course not be read too literally.  E.g. one can easily imagine a situation where not all thread management is done by the application (so not user-level thread according to above), but where switching between threads does not always require the kernel (so not kernel-level thread).  Instead, I think the points are meant as "typical features".

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

Hope this gives you some insight
How does a program know when it is executing in kernel mode vs. user mode for each of the following: Linux, DOS, Windows XP?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.