In: Computer Science
In operating systems:
Why might threads be particularly useful in writing an application such as a web browser with multiple tabs?
1) Thread:
i) 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.
ii) A thread is a basic unit of CPU utilisation, consisting of a program counter , a stack and a set of registers.(and thread ID).
iii) Traditional (heavyweight) processes have a single thread of control.i.e. one program counter, one sequence of instructions.
2) Multiple Threads
i) Single process executes using multiple threads, each having their own program counter, stack and set of registers, but sharing common code, data, and certain structures such as open files.
ii)Above points are shown diagrametically below:
3) Threads are very useful in modern programming whenever a process has multiple tasks to perform independently of the others.
4) When one of the task may block, and it is desired to allow other tasks to proceed without blocking.
5) Multiple threading is useful in the application like web browser with multiple tabs because, Multiple threads allow for the multiple requests to be satisfied simultaneously, without having to service request sequentially or to fork off separate processes for every incoming request.
6) Following diagram shows the architecture of multithreaded server.
7) Responsiveness is one of the benefit of using multi threading.Due to responsiveness one thread may provide rapid response while otjer threads are blocked or slowed down doing intensive calculations.
8)Creating and managing threds is much faster than performing the same tasks for processes.
9) Multi threaded application may be split amongst available processors.