Prerequisite – Thread, Difference between multitasking, multithreading and multiprocessing
A multitasking operating system is an operating system that gives you the perception of 2 or more tasks/jobs/processes running at the same time. It does this by dividing system resources amongst these tasks/jobs/processes and switching between the tasks/jobs/processes while they are executing over and over again. Usually CPU processes only one task at a time but the switching is so fast that it looks like CPU is executing multiple processes at a time. They can support either preemptive multitasking, where the OS doles out time to applications (virtually all modern OSes) or cooperative multitasking, where the OS waits for the program to give back control (Windows 3.x, Mac OS 9 and earlier), leading to hangs and crashes. Also known as Timesharing, multitasking is a logical extension of multiprogramming.
Multitasking programming is of two types –
- Process-based Multitasking
- Thread-based Multitasking.
Process Based Multitasking Programming –
- In process based multitasking two or more processes and programs can be run concurrently.
- In process based multitasking a process or a program is the smallest unit.
- Program is a bigger unit.
- Process based multitasking requires more overhead.
- Process requires its own address space.
- Process to Process communication is expensive.
- Here, it is unable to gain access over idle time of CPU.
- It is comparatively heavy weight.
- It has slower data rate multi-tasking.
Example – We can listen to music and browse internet at the same time. The processes in this example are the music player and browser.
Thread Based Multitasking Programming –
- In thread based multitasking two or more threads can be run concurrently.
- In thread based multitasking a thread is the smallest unit.
- Thread is a smaller unit.
- Thread based multitasking requires less overhead.
- Threads share same address space.
- Thread to Thread communication is not expensive.
- It allows taking gain access over idle time taken by CPU.
- It is comparatively light weight.
- It has faster data rate multi-tasking.
Examples – Using a browser we can navigate through the webpage and at the same time download a file. In this example, navigation is one thread and downloading is another thread. Also in a word-processing application like MS Word, we can type text in one thread and spell checker checks for mistakes in another thread.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Difference between Multiprogramming, multitasking, multithreading and multiprocessing
- Difference between Multiprogramming and Multitasking
- Difference between Preemptive and Cooperative Multitasking
- Sum and Product of minimum and maximum element of an Array
- Sum and Product of maximum and minimum element in Binary Tree
- Sum and Product of minimum and maximum element of Binary Search Tree
- Sum and product of k smallest and k largest prime numbers in the array
- Sum and product of k smallest and k largest composite numbers in the array
- Difference between Stop and Wait, GoBackN and Selective Repeat
- Difference and similarities between HashSet, LinkedHashSet and TreeSet in Java
- Difference between Stop and Wait protocol and Sliding Window protocol
- What are the differences and Similarities Between Lumen and Laravel?
- Stop and Wait protocol, its problems and solutions
- Analysis and Design of Combinational and Sequential circuits
- Generate an array of given size with equal count and sum of odd and even numbers
- Data Structures and Algorithms | Set 1
- Data Structures and Algorithms | Set 3
- Data Structures and Algorithms | Set 2
- Data Structures and Algorithms | Set 4
- Data Structures and Algorithms | Set 5
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.