Home »
Operating System
Multitasking and Multithreading in Operating System
In this tutorial, we will learn about the multitasking operating system and multithreading operating system. this article also comprises working and differences between multitasking and multithreading operating system.
By Monika Jha Last updated : May 05, 2023
What is Multitasking Operating System?
When any program is running it is referred to as a task. In a Multitasking Operating System, two or more tasks are active simultaneously.
In this, we stop one task temporarily to work one another. It also means that the computer can work with more than one program at a time.
For instance, you can fetch information from one database on the screen analyzing data, while the computer is sorting data from another database, on the other hand performing calculations on a separate worksheet.
Another example is, In modern operating systems, we can play MP3 music, edit documents in Microsoft Word, surfing the Google Chrome all are simultaneous.
It is not same as "multiple loading" of applications, also referred to as "context switching" or "task switching," which is what happens when you use MultiFinder or System 7 on the Macintosh or the DOS task switcher.
In Context switching, several applications can be open, but only one application is working at a time. Multitasking based on the time-sharing along with context switching.
Working of Multitasking System
In a time-sharing system, each process is assigned some specific amount of time for this time slice a process can be executed. For instance, there are 4 processes P1, P2, P3 ready to be executed by the processor. Each of them is assigned some time slice for which they will execute e.g time quantum of 4 nanoseconds (4 ns). When one process begins execution (say P3), it executes for that quantum of time (4 ns). After 4 ns the CPU starts the execution of the other process (say P1) for the specified quantum of time.
By this CPU shares the time between all processes and execute according to the time slice. As soon as time slice of one process expires, another process ready to begin its execution.
Here the concept of context switch is occurring but it is occurring so fast. While jobs or tasks are running the user thinks that those multiple processes/ jobs are executing simultaneously and separately interact with the system.
But literally, only one process/ job is executing at a particular point of time. In the multitasking system, the concept of time-sharing is introduced because each running process takes only a fair quantum of the CPU time.
Types of Multitasking Operating System
- True multitasking
Two or more tasks are carried out by the Operating system rather than switching from one process to another. This capacity of Operating system is true multitasking.
- Preemptive multitasking
Preemptive multitasking is a task in which an operating system uses criteria to make a decision how long to allocate to any one task before giving another task a turn to use the operating system. If the Operating System takes control from one job and giving it to another job, it is called preemption.
A common criterion for preempting is simply is time slicing, this type of system is sometimes called a time-sharing operating system. In some operating systems, some applications have a higher priority than the other applications, It is necessary to give control to the higher priority process or task as soon as they are initiated.
What is Multithreading Operating System?
A flow of control is called a thread. A program is a set of instructions which constitute different parts of a single program. Each different part of the program is referred to as thread of the program.
A process that has only one flow of control is referred to as a single thread.
A process having multiple flows of control is referred to as single multithread (heavyweight process).
Example: In a word processor, one thread (t1) is for displaying graphics, second thread (t2) for reading keystrokes from the user and a third thread (t3) for performing spelling and grammar checking in the background.
Working of Multithreading Operating System
Threads such as child processes that use the parent process resources but execute on its own. But in case of a GUI. If we are performing a calculation on the GUI (which is taking a very long time to finish). Now we can not interact with the rest of the GUI until this command finishes its execution.
To be able to interact with the rest of the GUI, this command of calculation should be assigned to another separate thread. So at this point of time, two threads will be executing i.e. one for calculation, and one for the rest of the GUI. Hence for a single process, we use multiple threads for multiple functionalities.
Advantages of Multithreading Operating System
- Responsiveness – It allows a program to continue its execution even if part of it is blocked or is performing a lengthy operation thereby increasing the responsiveness to the user.
- Resource sharing – The memory and the resources of the process shared by threads to which they belong.
- Utilization of Multiprocessor Architecture – In Multiprocessor Architecture each thread may be running in parallel on a different processor. Multithreading on a multi-CPU machine increases concurrency.
- Economy – It is costly to allocate memory and resources for process creation. Threads share resources of the processes to which they belong, it is more economical to create threads.
Differences Between Multitasking and Multithreading Operating System
The following are the main differences between multitasking and Multithreading Operating System:
- In the multitasking system, multiple processes can be executed whereas in multithreading a single process with multiple threads can be executing at the same time.
- Multithreading helps when more than one client uses it. For instance, In DB. While I'm typing something, there would be someone else, doing the same type of job. not more than one person will be able to do the same kind of job If DB is not having a multithread option.
- It is time-consuming to create and manage processes than threads.