Multitasking vs Multithreading vs Multiprocessing

Aqib Ilyas
CodeX
Published in
3 min readAug 4, 2022

Computers today are very smart and can perform multiple operations at once. This ability of computers to run multiple tasks at the same time is called Multitasking.

A single core computer can never run multiple programs at the same time. What it does is that it gives a little bit of time to every program being executed creating an illusion of multitasking. For example, if we run two different programs or multiple instances of the same program on a single core, it will run 1 instance/program for a few seconds/milliseconds and then switch to the other program being executed and give it resources for some time and so on. This is called multitasking, where the computer uses its context switching ability to switch back and forth between multiple programs. This will definitely increase program execution time as multiple programs are sharing the same CPU resources and time.

geeksforgeeks.com

What if a program being executed has multiple threads?

A thread is the smallest piece of instructions from a large program. If a single program/process needs to do multiple tasks concurrently, it divides these tasks into threads. For instance, an application has to download the data and update the progress bar as well, it can download data in one thread and update UI in the other. Some important properties of threads are:

  • sub-tasks of the main program
  • Share CPU resources with each other
  • can be paused, stopped, and resumed

This way of executing multiple threads/tasks of a single process/program is called Multithreading.

Multithreading is a kind of multitasking where multiple tasks being executed are part of same program.

Now let’s assume we have a dual-core computer and we try to run a single non-threaded program, the CPU will execute that program in a single core and provide all its resources while the other core will sit free. When we try to run multiple non-threaded programs on a multi-core CPU, the computer will again utilize its multitasking ability and give each program, resources from its cores. A single program will run completely on 1 core while the other on the second and so on. CPU will give some time to each individual program being executed on its all cores. This is called Multiprocessing.

Multiple non-threaded programs share CPU cores but they will always complete their execution on a core where an execution was first started.

When we try to run the multi-threaded program on a multi-core CPU, the CPU will utilize its cores and run threads on all available cores. This is multi-threading on a multi-core CPU and this is also called Multiprocessing.

To conclude, multithreading and multiprocessing utilize the computer’s multitasking ability which in turn use context switching.

  • In multitasking, multiple programs and threads share the same CPU core.
  • In multithreading, different threads of the same program share the same CPU core and execute concurrently.
  • In multiprocessing, multiple programs and even multiple threads of the same program utilize all CPU cores available and this is the truest form of parallel processing where the CPU executes multiple programs or threads in parallel on its different cores.

--

--