Disclosure: This article may contain affiliate links. When you purchase, we may earn an affiliate commission.

3 Difference between multi-threading and multitasking? Answer

In the programming world, there are two main ways to improve the throughput of a program,  by using multi-threading and by using multitasking. Both take advantage of parallelism to efficiently utilize the immense power of the CPU and improve the throughput of your program. Actually, multi-threading is nothing but thread-based multitasking. Since the difference between multi-threading and multi-tasking is an important fresher programming interview question and also often ask in viva or oral exams on computer science graduation courses, I thought to jot down a couple of important points together. This article is the result of those points and can be handy when you quickly want to know the key difference between multi-threading and multi-tasking in concurrent programming.

Difference between multithreading and multi-tasking

1) In multitasking, several programs are executed concurrently like Java compiler and a Java IDE like Netbeans or Eclipse, while in multi-threading multiple threads execute either the same or different parts of the program multiple times at the same time.

2) Multi-threading is more granular than multi-tasking. In multitasking, the CPU switches between multiple programs to complete their execution in real-time, while in multi-threading CPU switches between multiple threads of the same program. 

Remember, switching between multiple processes has more context switching cost than switching between multiple threads of the same program.

3) Processes are heavyweight as compared to threads, they require their own address space, which means multi-tasking is heavy compared to multithreading. Inter-process communication is expensive and limited and context switching from one process to another is expensive and limited.  See the difference between a Process and a Thread to learn more.

Here is the summary of the difference between multitasking and multithreading in concurrent programming:

Difference between multithreading and multitasking

That's all about the difference between multitasking and multithreading. Both are used to parallelize things in order to take full advantage of expensive hardware and CPU.  Multitasking is an ability of a computer to execute multiple programs at the same time while multi-threading is the ability of a process to execute multiple threads at the same time.  Sometimes multitasking is useful and other times multi-threading.

No comments:

Post a Comment

Feel free to comment, ask questions if you have any doubt.