Multithreading | Operating System - Computer Science Engineering (CSE) PDF Download

Multithreading in Operating System

A thread is a path which is followed during a program’s execution. Majority of programs written now a days run as a single thread. Lets say, for example a program is not capable of reading keystrokes while making drawings. These tasks cannot be executed by the program at the same time. This problem can be solved through multitasking so that two or more tasks can be executed simultaneously.
Multitasking is of two types: Processor based and thread based. Processor based multitasking is totally managed by the OS, however multitasking through multithreading can be controlled by the programmer to some extent.
The concept of multi-threading needs proper understanding of these two terms – a process and a thread. A process is a program being executed. A process can be further divided into independent units known as threads.
A thread is like a small light-weight process within a process. Or we can say a collection of threads is what is known as a process.

Multithreading | Operating System - Computer Science Engineering (CSE)

Applications
Threading is used widely in almost every field. Most widely it is seen over the internet now days where we are using transaction processing of every type like recharges, online transfer, banking etc. Threading is a segment which divide the code into small parts that are of very light weight and has less burden on CPU memory so that it can be easily worked out and can achieve goal in desired field. The concept of threading is designed due to the problem of fast and regular changes in technology and less the work in different areas due to less application. Then as says “need is the generation of creation or innovation” hence by following this approach human mind develop the concept of thread to enhance the capability of programming.

Multi Threading Models in Process Management

Many operating systems support kernel thread and user thread in a combined way. Example of such system is Solaris. Multi threading model are of three types.

  • Many to many model.
  • Many to one model.
  • one to one model.
  1. Many to Many Model
    In this model, we have multiple user threads multiplex to same or lesser number of kernel level threads. Number of kernel level threads are specific to the machine, advantage of this model is if a user thread is blocked we can schedule others user thread to other kernel thread. Thus, System doesn’t block if a particular thread is blocked.
    Multithreading | Operating System - Computer Science Engineering (CSE)
  2. Many to One Model
    In this model, we have multiple user threads mapped to one kernel thread. In this model when a user thread makes a blocking system call entire process blocks. As we have only one kernel thread and only one user thread can access kernel at a time, so multiple threads are not able access multiprocessor at the same time.
    Multithreading | Operating System - Computer Science Engineering (CSE)
  3. One to One Model
    In this model, one to one relationship between kernel and user thread. In this model multiple thread can run on multiple processor. Problem with this model is that creating a user thread requires the corresponding kernel thread.
    Multithreading | Operating System - Computer Science Engineering (CSE)

Benefits of Multithreading in Operating System
The benefits of multi threaded programming can be broken down into four major categories:

  1. Responsiveness
    Multithreading in an interactive application may allow a program to continue running even if a part of it is blocked or is performing a lengthy operation, thereby increasing responsiveness to the user.
    In a non multi threaded environment, a server listens to the port for some request and when the request comes, it processes the request and then resume listening to another request. The time taken while processing of request makes other users wait unnecessarily. Instead a better approach would be to pass the request to a worker thread and continue listening to port.
    For example, a multi threaded web browser allow user interaction in one thread while an video is being loaded in another thread. So instead of waiting for the whole web-page to load the user can continue viewing some portion of the web-page.
  2. Resource Sharing
    Processes may share resources only through techniques such as-
    • Message Passing
    • Shared Memory
      Such techniques must be explicitly organized by programmer. However, threads share the memory and the resources of the process to which they belong by default.
      The benefit of sharing code and data is that it allows an application to have several threads of activity within same address space.
  3. Economy
    Allocating memory and resources for process creation is a costly job in terms of time and space.
    Since, threads share memory with the process it belongs, it is more economical to create and context switch threads. Generally much more time is consumed in creating and managing processes than in threads.
    In Solaris, for example, creating process is 30 times slower than creating threads and context switching is 5 times slower.
  4. Scalability
    The benefits of multi-programming greatly increase in case of multiprocessor architecture, where threads may be running parallel on multiple processors. If there is only one thread then it is not possible to divide the processes into smaller tasks that different processors can perform.
    Single threaded process can run only on one processor regardless of how many processors are available.
    Multi-threading on a multiple CPU machine increases parallelism.
The document Multithreading | Operating System - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Operating System.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
10 videos|99 docs|33 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Multithreading - Operating System - Computer Science Engineering (CSE)

1. What is multithreading in operating systems?
Ans. Multithreading in operating systems refers to the ability of a program or process to execute multiple threads concurrently within a single process. Each thread represents an independent sequence of instructions, allowing for parallel execution and efficient utilization of system resources.
2. How does multithreading differ from multiprocessing?
Ans. Multithreading and multiprocessing both involve executing multiple tasks concurrently, but they differ in how they handle resources. In multiprocessing, each task (or process) has its own memory space and resources, while in multithreading, multiple threads share the same memory space and resources within a single process.
3. What are the advantages of using multithreading in operating systems?
Ans. Multithreading offers several advantages in operating systems, including improved performance through parallel execution, enhanced responsiveness by allowing tasks to run concurrently, efficient resource utilization, and simplified program design by dividing complex tasks into smaller threads.
4. What are the potential challenges or risks associated with multithreading?
Ans. Multithreading introduces certain challenges, such as race conditions (where threads access shared resources simultaneously, leading to unexpected behavior), synchronization issues (ensuring proper coordination between threads), and increased complexity in debugging and troubleshooting due to the interleaved execution of threads.
5. How does an operating system schedule and manage multiple threads?
Ans. The operating system uses scheduling algorithms to manage and schedule threads. These algorithms determine the order and duration of thread execution, taking into account factors such as thread priority, resource availability, and fairness. Common scheduling algorithms include round-robin, priority-based, and multilevel feedback queue. The operating system also provides synchronization primitives, such as locks and semaphores, to control access to shared resources and prevent race conditions.
10 videos|99 docs|33 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Multithreading | Operating System - Computer Science Engineering (CSE)

,

MCQs

,

Summary

,

Multithreading | Operating System - Computer Science Engineering (CSE)

,

Free

,

ppt

,

pdf

,

Multithreading | Operating System - Computer Science Engineering (CSE)

,

mock tests for examination

,

Objective type Questions

,

video lectures

,

Sample Paper

,

Viva Questions

,

Previous Year Questions with Solutions

,

Important questions

,

Semester Notes

,

Exam

,

practice quizzes

,

study material

,

past year papers

,

shortcuts and tricks

,

Extra Questions

;