[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Difference between Userlevel Threads and Kernel level threads?

Posted on 2004-11-01
Medium Priority
Last Modified: 2008-03-17
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.

Question by:rafayali
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

Physicistm earned 200 total points
ID: 12461776
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

Expert Comment

ID: 25203178
How does a program know when it is executing in kernel mode vs. user mode for each of the following: Linux, DOS, Windows XP?

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally Windows/Microsoft Updates will fail to update. We have found a code that will delete all temporary files and re-register all dll's related to Windows/Microsoft Updates! This works 99% of the time to get the updates working again! The…
Sometimes a user will call me frantically, explaining that something has gone wrong and they have tried everything (read - they have messed it up more and now need someone to clean up) and it still does no good, can I help them?!  Usually the standa…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question