Threads are implemented in following two ways:

  • User Level Threads -- User managed threads
  • Kernel Level Threads -- Operating System managed threads acting on kernel, an operating system core

User Level Threads

User thread are supported at user level. In this case, the thread management kernel is not aware of the existence of threads. The thread library contains code for creating and destroying threads, for passing message and data between threads, for scheduling thread execution and for saving and restoring thread contexts. In fact, the kernel knows nothing about user-level threads and manages them as if they were single-threaded processes.

Advantages

  • The most obvious advantage of this technique is that a user-level threads package can be implemented on an Operating System that does not support threads.
  • User-level thread does not require modification to operating system.
  • Simple Representation: Each thread is represented simply by a PC, registers, stack and a small control block, all stored in the user process address space.
  • Simple Management: This simply means that creating a thread, switching between threads and synchronization between threads can all be done without intervention of the Kernel.
  • Fast and Efficient: Thread switching is not much more expensive than a procedure call.

Disadvantages

  • There is a lack of coordination between threads and operating system kernel. Therefore, process as whole gets one time slice irrespective of whether process has one thread or 1000 threads It is up to each thread to relinquish control to other threads.
  • User-level thread requires non-blocking systems call e., a multithreaded kernel. Otherwise, entire process will blocked in the kernel, even if there are run able threads left in the processes. For example, if one thread causes a page fault, the process blocks.

Kernel-Level Threads

In this method, the kernel knows about and manages the threads. Instead of thread table in each process, the kernel has a thread table that keeps track of all threads in the system. Scheduling by the Kernel is done on a thread basis. The Kernel performs thread creation, scheduling and management in Kernel space. Kernel threads are generally slower to create and manage than the user threads.

Advantages

  • Because kernel has full knowledge of all threads, Scheduler may decide to give more time to a process having large number of threads than process having small number of threads.
  • Kernel-level threads are especially good for applications that frequently block.

Disadvantages

  • The kernel-level threads are slow and inefficient. For instance, threads operations are hundreds of times slower than that of user-level threads.
  • Since kernel must manage and schedule threads as well as It require a full thread control block (TCB) for each thread to maintain information about threads. As a result there is significant overhead and increased in kernel complexity.

Difference

User-Level Threads

Kernel-Level Thread

User-level threads are faster to create and manage.

Kernel-level threads are slower to create and manage.

Implementation is by a thread library at the user level.

Operating system supports creation of Kernel threads.

User-level thread is generic and can run on any operating system.

Kernel-level thread is specific to the operating system.

Multi-threaded applications cannot take advantage of multiprocessing.

Kernel routines themselves can be multithreaded.

Combined/Hybrid Thread

Some operating system provides a combined user level thread and Kernel level thread facility. Solaris is a good example of this combined approach. In a combined system, multiple threads within the same application can run in parallel on multiple processors and a blocking system call need not block the entire process.