There is a lot of misconception regarding what is Multi-threading and what is Multi-tasking. People seem to confuse both of these concepts. When I was starting to learn about these topics, things were not easy to figure out. I do not know if this was intentional or not but there was not a singly, well-compiled resource from which you can learn; how to differentiate between multi-threading and multi-tasking in computers.
After lots and lots of reading, I have tried to explain this concept to you. Keep in mind that this will be a very simple and concise text that can be easily grasped by a beginner. We will not go that deep in the technicalities as it can scare someone who is just trying to gain some simple knowledge.
I will try to explain these concepts with a mix of real-life examples and some technical terms. Do not be scared, once you know how stuff happens then you can go on and explore more.
Let us first start with multi-tasking in computers.
Multi-tasking in Computers
Imagine that you are working as a secretary in some office. You have multiple things you have to do currently. You can also call these things as tasks. Each of these tasks requires your focus and attention span. Say you have to call and confirm the CEO’s meeting time, on the other hand, you have to book a time slot for your presentation, and you also have to stack some folders.
All these jobs or *tasks* you have to do has to be done right now. So what you will do is give each of them some time. You will divide your attention or time to complete these tasks. First, you will stack your folders and then quickly respond to email and then do something else. This might be really hard for humans as it takes an average of about 25 minutes to return to the work that you were doing before the interruption. You can read this study here. Considering this example, there are A LOT of tasks secretory has to perform. But hey, that is why computers were invented right?
When you open an application (it can be anything, a window, text editor, or a browser) on the computer and then you open another program, the computer divides the “attention span”. The two applications that you have opened are two tasks. The computer executes these more than one task by giving priority to one task for a specific period of time and then it moves to the other. This is happening so quickly that the user does not even notice. But if the task is really CPU or IO Intensive you will start to experience latency issues. That is when you’ll say that the computer is freezing or has crashed.
To sum it up, we can say that, Multitasking is achieved when the CPU schedules that which task would be running at a given time, and when will the other tasks will get a turn. The act of scheduling or assigning CPU to another task is called Context switching or scheduling. When context switching is done really quickly, it creates an illusion that the computer is executing both of the tasks at the same time.
Now we will loot at multi-threading in computers
Multi-Threading in Computers
You can imagine multi-threading in computers as dividing one task into many parts. While multi-tasking in computers concerns with scheduling two or more than 2 tasks. Multi-threading is concerned with running different parts of the same task concurrently. Keeping up with the secretory example, say you have to schedule the meeting, you will at least have to do 2 basic things. First of all, you will have to find the time slot which is perfect but you will have also have to inform the participants. You can do both of these tasks (Keep in mind these 2 processes are a part of one main task: Scheduling a meeting) step by step, you cannot perform both of the tasks at the same time. But here comes a computer, once again outperforming a human.
When you execute a program or a task, the computer calls it a Process. This process, if programmed suitably, can be assigned sub-processes or Threads. When you open an MS Word document, the computer calls it a process. You can do so many things, you can edit, print, save, etc. The processes running in the background of one main task are called sub-processes or thread
But have you ever noticed that when you are saving a document, you cannot write anything else or when you are writing you can’t change the text color? The computer is just so fast you cannot notice it but both of these things cannot happen at once. But when you are playing a game, you can hear the sounds, you can see objects, you can run while hearing things. The game is a process or a task, the sounds that you hear, the zombies that you shoot, the sprint that you make are all sub-processes.
In multi-threading, more than one core of the CPU is used at a time. The executions are happening in parallel. Sometimes these executions depend on the results of other executions. Multi-threading is done when a program is CPU intensive. You can divide a task into multiple threads to quickly perform it.
Let us make a list of differences in multi-tasking and multi-threading in computers
Differences in Multi-threading and Multi-tasking in Computers
Multi-tasking in computers is done by scheduling tasks and prioritizing them, which is also known as context-switching. Multi-threading in computers is done by involving multiple cores of the CPU.
Multi-tasking in computers is not concerned with cores of the CPU, it can be done by a single-core computer too, it is just slow compared to multiple cores. Multi-threading concerns with the cores of the CPU and use resources. Implementation of threads requires more resources. That is why you cannot play GTA V on Pentium 3 or Core 2 Duo. As they have many internal sub-processes that cannot be handled effectively by a single-core computer
Multi-tasking is done by the operating system to handle multiple tasks. While multi-threading in computers can be implemented in the program that you are making. As the program, you are making is a task, it depends on you whether you want to implement multi-threading or not.
Multi-tasking in computers is concerned with primary memory or RAM. All the executing tasks are stored on the RAM, thus slowing down the overall speed of the computer if too many tasks are opened at the same time. Multi-threading in computers requires a CPU with multiple cores so the task which is performing multi-threading can ask for the threads from the OS.
After reading this article, I hope that now you will have a general sense of these topics. Once you develop a good foundation there is nothing that is stopping you from learning more. Now you can learn how RAM aids in achieving multitasking and how a good CPU can let you play GTA V.
If you liked this article and found it helpful, make sure to share it and if you want to point something out, you can comment too.