However, because each CPU are separate, it may happen that one CPU may not have anything to process. One processor may sit idle, and the other may be overloaded with the specific processes. In such a case, the process and resources are shared dynamically among the processors.
What is Multithreading?
Multithreading is a program execution technique that allows a single process to have multiple code segments (like threads). It also runs concurrently within the “context” of that process. Multi-threaded applications are applications that have two or more threads that run concurrently. Therefore, it is also known as concurrency.
Characteristics of Multiprocessing
Here are the essential features of Multiprocessing:
Multiprocessing are classified according to the way their memory is organized. Multiprocessing improves the reliability of the system Multiprocessing can improve performance by decomposing a program into parallel executable tasks.
Characteristics of Multithreading
Here are important aspects of multithreading:
In the multithreading process, each thread runs parallel to each other. Threads do not allow you to separate the memory area. Therefore it saves memory and offers a better application performance
Difference Between Multiprocessing and Multithreading
Here are important differences between Multithreading vs Multiprocessing
Advantage of Multiprocessing
Here are cons/ pros of Multiprocessing:
The biggest advantage of a multiprocessor system is that it helps you to get more work done in a shorter period. The code is usually straightforward. Takes advantage of multiple CPU & cores Helps you to avoid GIL limitations for CPython Remove synchronization primitives unless if you use shared memory. Child processes are mostly interruptible/killable It helps you to get work done in a shorter period. These types of systems should be used when very high speed is required to process a large volume of data. Multiprocessing systems save money compared to single processor systems as processors can share peripherals and power supplies.
Advantage of Multithreading
Here, are pros/benefits of multithreading:
Threads share the same address space Threads are lightweight which has a low memory footprint The cost of communication between threads is low. Access to memory state from another context is easier It allows you to make responsive UIs easily An ideal option for I/O-bound applications Takes lesser time to switch between two threads within the shared memory and time to terminate Threads are faster to start than processes and also faster in task-switching. All Threads share a process memory pool that is very beneficial. Takes lesser time to create a new thread in the existing process than a new process
Disadvantage of Multiprocessing
Here, are cons/drawback by using Multiprocessing operating system
IPC(Inter-Process Communication) a quite complicated with more overhead Has a larger memory footprint
Disadvantage of multithreading
Here, are cons/ drawbacks of using multithreading system :
Multithreading system is not interruptible/killable If not following a command queue and message pump model then manual use of synchronization needed which becomes a necessity Code is usually harder to understand and increases the potential for race conditions increases dramatically