what are threads? what is multithreading? definition with examples and advantages of multithreading. - Cyber security & Technology

Breaking

Thursday, August 9, 2018

what are threads? what is multithreading? definition with examples and advantages of multithreading.






THREADS

Thread definition

·        A thread is a single sequential flow of execution of the tasks of a process.

·        A thread is a lightweight process and the smallest unit of CPU utilization. Thus a thread is like a little miniprocess.

·        Each thread has a thread id, a program counter, a register set and a stack.

·        A thread undergoes different states such as new, ready, running, waiting and terminated similar to that of a process.

·        However, a thread is not a program as it cannot run on its own. It runs within a program.

Multithreading

·        A process can have single thread of control or multiple threads of control.

·        If a process has a single thread of control, it can perform only one task at a time. For example, if a process is running a word-processor program, a single thread of instructions is being executed. In such a situation the user could not simultaneously type in characters and run the spell checker within the same process.

·        Many modern operating system have extended the process concept to allow a process to have multiple threads of execution. Thus allowing the process to perform multiple tasks at the same time. This concept is known as multithreading.                                                                                                                   For example, the tasks in a web browser are divided into multiple threads: downloading the images, downloading the text and displaying images and text. While one thread is busy in downloading the images, another thread displays the text.

·        The various operating systems that implements the concept of multithreading are windows NT 4.0, windows 95, windows 98, windows 2000, UNIX.

·        In multithreading, a thread can share its code section, data section and operating system resources such as open files and signals with the other threads of same process.

·        The concept of single-threaded& multithreaded process is depicted in fig.



Advantages of multithreading

The various advantages of multithreading are:

1.      Responsiveness : In multithreading the responsiveness of process towards a user is high. In case of interactive applications, if part of a program is blocked or is performing a lengthy operation, multithreading still allows a program to continue to run.                                                            For example : a multithreaded web browser could still allow user interaction in one thread while an image is being loaded in another thread.

2.      Resource sharing : All the threads of a process share memory as well as the resources that a process is using.

3.      Economy : Threads are easier to create and maintain as compared to processes. Moreover it is less time consuming to create a thread and more economical to context switch a thread. For example, In solaris 2, creating a process is about 30 times slower than is creating a thread and context switching is about five times slower.

4.      Utilization of multiprocessor architectures. The benefit of multithreading can be greatly increased in a multiprocessor architecture, where each thread may be running in parallel on different processor. In this way concurrency is increased as multiple threads are running on multiple processors.

No comments:

Post a Comment