SiteMap  | About    

Multiprocessing vs Threading

What is Threading?

A thread of a process means a code segment of a process , which has its own thread ID, program counter, registers and stack and can execute independently . A thread of execution is the smallest sequence of programmed instructions that can be managed independently by a scheduler , which is typically a part of the operating system. Multithreading is a type of execution model that allows multiple threads to exist within the context.

What is Multiprocessing?

A process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently .

A multiprocessing system is one which has more than two processors. The CPUs are added to the system to increase the computing speed of the system. Each CPU has its own set of registers and main memory. Just because CPUs are separate, it may happen that one CPU must not have anything to process and may sit idle and the other may be overloaded with the processes.

Multiprocessing vs Threading

Multiprocessing and Multithreading both adds performance to the system. The threading module uses threads, the multiprocessing module uses processes. The difference is that threads run in the same memory space, while processes have separate memory. This makes it a bit harder to share objects between processes with multiprocessing. Since threads use the same memory, precautions have to be taken or two threads will write to the same memory at the same time. The key advantage is isolation . A crashing process won't bring down other processes, whereas a crashing thread will probably wreak havoc with other threads.

Multiple threads can exist in a single process . The threads that belong to the same process share the same memory area (can read from and write to the very same variables, and can interfere with one another). On the contrary, different processes live in different memory areas , and each of them has its own variables. In order to communicate, processes have to use other channels (files, pipes or sockets).

Creating a process can consume time and even exhaust the system resources. However creating threads is economical as threads belonging to the same process share the belongings of that process. About performance , it depends on what OS you are using where speed is concerned. In Windows processes are costly so threads would be better in windows but in unix processes are faster than their windows variants so using processes in unix is much safer plus quick to spawn. (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.