Threads in operating system

 
Topic Outline
  • Threads
  • Difference between thread and process
  • Types of Threads
    • Kernel Level Thread
    • User Level Thread
  • Multithreading
  • Advantages
    • Resource Sharing
    • Responsiveness
    • Utilization of Multiprocessor Architecture
  • Multithreading Models
    • Many to One Model
    • One to One Model
    • Many to Many Model


Threads

Thread is a basic unit of CPU utilization. Thread is also called a lightweight process. Thread is a process within a process but it does not have its own process control block. In a process, multiple threads are created. In a process, multiple threads allow multiple executions. 

 The thread consists of the following things.

  • Thread ID
  • Register
  • Program counter
  • Stack

Difference between threads and process.

Threads 

Process 

In threads no system call is 

involved. 

In a process system call is involved. 

Thread is a lightweight process. 

The Process is heavyweight

If the thread ends the process

 may still run. 

If the process ends, threads in it also end. 

The thread has no data and heap

 segment. 

The process has code, data, and heap segments. 

Thread cannot exist without a process. 

In a process must be at least

 one thread. 

The creation of threads and 

context switching is inexpensive. 

The creation of threads and context switching is expensive. 

Types of Threads

Two types of threads are to be managed in a modern operating system.

  • Kernel level threads
  • User-level threads 
1: Kernel level threads

Kernel-level threads are managed by the operating system. The modern operating system must support kernel-level threads. They allow the kernel to perform multiple tasks.
Advantages

  • Kernel has full detailed knowledge of all threads.
  • These threads are good for applications that are blocked frequently.

Disadvantages 

  • Kernel level threads are slow.
  • Kernel must manage and schedule threads as well as the processes.

2: User level threads

User-level threads are managed by user-level libraries instead of system calls. Thread switching does not need to call the operating system. The kernel is not aware of the existence of user-level threads. It manages these threads as single-threaded processes.
Advantages

  • User-level threads are very fast.
  • User-level threads are simple to manage.
  • Switching between threads can be done without the kernel.

Disadvantages

  • Kernel assigns only one process to a processor at a time.
  • Lack of coordination between threads and operating system kernel.
Multithreading

Multithreading allows the operating system to execute different threads at the same time. Application is implemented as a separate process with many threads. The latest software for modern computer systems is multithreaded.
For example

Web browsers can use one thread to get data from the network. Web browsers can use a second thread to display images and user interfaces to you.
According to the server perspective, many clients may be accessing the server at the same time. So for many clients making a separate process for every request and a separate provide service on that request is time and resource consuming. So, multithreading allows the server to make a single process with multiple threads and those threads manage all work.

  • Multithreading is very efficient.
  • Operating system kernels are also multithreaded.
  • Solaris creates threads in the kernel for handling interrupts.
  • Linux uses kernel thread to manage the amount of free memory in the system.

Advantages

  •  Resource Sharing

Every process demands new resources but when it comes to threads, threads use the common resource of their process.
  • Responsiveness
Multithreading increase the responsiveness of the process. A process consists of multiple threads. If one thread is busy or blocked in a lengthy calculation, another thread may execute.

  • Utilization of Multiprocessor Architecture

Multiprocessor architecture provides the facility to run more than one task in parallel so you can utilize it using the concept of multithreading.

Multithreading Models

1: Many to One Model

In this model, many user-level threads are mapped to one kernel thread. It is implemented in user space so it is efficient. In this model, only one thread can access the kernel at a time. If one thread blocks, the remaining threads will also block. Green threads for Solaris and  GNU portable threads are implemented by many to one model.

 

2: One to One Model

In this model, each user thread is mapped to a kernel thread. If one thread is, blocked, remaining all threads will never be blocked. This model is used by Linux and Windows XP.

 

3: Many to Many Model

In this model, many user-level threads are mapped to equal or smaller levels of kernel thread. Kernel threads can run in parallel on a multiprocessor system. If one thread is blocked, the kernel can execute another thread. It is used by Solaris, HP-UX.

 

Comments

Popular Posts

Computer Abbreviation

Transport Layer

Introduction to Database

Types of database

Display devices

Shortcut keys of computer

History of Computer