Difference between Userlevel Threads and Kernel level threads?

Posted on 2004-11-01
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
    LVL 3

    Accepted Solution

    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

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Lean Six Sigma Project Manager Certification

    There are many schools of thought around successful project management, but few as highly regarded as the Six Sigma and Lean methods. With 37 hours of learning, this training will explain concrete processes for increasing efficiency and limiting wasted time and effort.

    I don't know if many of you have made the great mistake of using the Cisco Thin Client model with the management software VXC. If you have then you are probably more then familiar with the incredibly clunky interface, the numerous work arounds, and …
    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 Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    933 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now