Multithreading and Multiprocessing

In this lecture, we will see Multithreading and Multiprocessing in details with its comparisons. let’s start with multi-threading,

What is Multi-threading?

Execution of multiple threads of a single process simultaneously with the help of single or multiple CPU’s is called Multi-threading.

If we have more than one CPU’s, then the threads of single process will execute on all the CPU’s. So, at a time, there may be only one process will be in execution state whether there is single CPU or Multiple CPU’s. Because of multiple threads of single Process.  

Context switching also occur in threading, When CPU move from one thread to another. As shown in diagram given below,

Example 01:

As we know a process may be made up of multiple threads of execution that execute instructions parallel.

To understand the concept of multi-threading let us take an example of a MS Word Process. A word process perform the following task at a time

  • Open MS Word
  • Writing Document
  • spelling checker
  • grammar checking

You do not have to open different word processors to do this concurrently (parallel). It is just possible in a single word processor because of multiple threads. Explain with diagram is given under,

 Example 02:

In multi-threading all open Tabs of chrome will works perfectly because chrome is one process and all opened tabs are threads of that Process. Downloading, listing audio and email are the some threads of chrome, which works parallel due to multi-threading.

Note: Process can be view from task manager. If chrome is one process then multiple chromes icons, looks in task manager, are its threads.

Advantages

  • increased responsiveness
  • Threads belonging to the same process share the belongings (Code, DATA, and File) of that process.
  • Less time in context switching
  • Parallel occurrence of tasks.
  • Decreased cost of system and its maintenance.

Disadvantages

  • Increased complexity.
  • Complex debugging and testing processes.
  • Result is sometimes unpredictable.
  • Increased difficulty to writing a program.

What is Multiprocessing?

So, two or more CPU’s present in the same computer and sharing the system resources like bus, memory, and other I/O devices is called Multiprocessing System.

Multiprocessing further categorized into symmetric multiprocessing and asymmetric multiprocessing.

In symmetric multiprocessing, all CPU’s are free to run any process in a system.

But in Asymmetric multiprocessing, there is a master-slave relationship among the CPU’s. The master CPU is responsible for allotting the process to slave CPU’s.

Advantages of the multiprocessing

  • Maximum Throughput: By increasing the number of CPU’s, more work can be done in a unit time.
  • Reliability Increased: As workload is distributed among several CPU’s.
  • Share Resources: CPU shares the memory, buses, peripherals etc.

Disadvantages of Multiprocessing

  • As more than CPU’s are working at a time. So, the coordination between these is very complex.
  • Buses, memory, and I/O devices are shared for all CPU’s. So, if any CPU is using some resource like buses. Then another processor has to wait for its turn. As a result throughput will decrease.
  • Highly costly because CPU is costly Hardware.

The basic difference between Multithreading and Multiprocessing is given under,

Multi-threading Multiprocessing
Threads of a process can execute on single or multiple CPU’s. multiple CPU’s are required for execution.

Advance Learning Related to this topic.

To get better results, Multiprocessing Can also be applied on Multi-programming, Multitasking and multi-threading. Let’s explain every term one by one.

Multiprocessing-Programming:

Multiprocessing-Multitasking:

Multiprocessing Multithreading:

Multitasking Vs. Multithreading

Multitasking Multithreading
More than one process get executed simultaneously. More than one threads of a process are get executed.
Multitasking  is Time-sharing process but CPU switch from process to process Multi-threading is also Time-sharing process but CPU switch from thread to thread of a process. After completion of all threads of that process, CPU switch to second process.
Heavy weight  Light weight

Multiprocessing Vs. Multitasking

Multiprocessing Multitasking/Multi-programming
It utilize multiple CPU’s. It utilize single CPU’s.
Multiprocessing allows parallel processing. i.e.

 

In Dual-core CPU, two process can run parallel and in Quad-core CPU four process can run parallel.

Only single process can run at a time. To execute other process, context switching take place.As only one CPU is available in the system.
Less time taken to complete the process. More time required to complete a process.
It is Much efficient to utilization of system resources like Hard disk, Registers because of multiprocessors. it is Less  efficient to utilization of system resources like Hard disk, Registers because of single processor.
Usually, it is more expensive. Usually, it is less expensive.

Help Other’s By Sharing…

Contact Us

Burewala, Vehari, Punjab, Pakistan

cstaleem1@gmail.com

Website: CStaleem.com

Pin It on Pinterest