Multithreading vs Multiprocessing

Multiprocessing

Multiprocessing is where multiple processes executes multiple tasks in parallel. 

Each process has its own memory and are independent of each other. Due to this multiprocessing is better suited for CPU intensive tasks.

Parallelism can achieved with Multi processing. This means multiple processes can be executed simultaneously on independent tasks thus improving overall performance.

Since processes have their own memory spawning them can be heavy and resource intensive.

Multithreading

Multithreading is where multiple threads executes a task concurrently.

A thread is lightweight alternative to a process. It doesn't have its own memory and instead uses shared memory.

Multithreading is better suited for IO bound processes since it doesn't have its own memory.

Concurrency can be achieved with Multithreading. Out of the thread pool at any given time only one thread is executing. This can be visualised by below diagram:


Comments