whatisthread

What is a thread in OS & how are these different from the traditional process?

Hello Friends, In this blog post I am going to discuss a thread in the operating system, and we will also compare this thread with a traditional process and will see how these differ from each other. We will understand this thread with a suitable example.

In a traditional operating system, each process has an address space and a single thread of control. In fact, that is almost the definition of a process.

Nevertheless, there is frequently a situation in which it is desirable to have multiple threads of control in the same address space running in quasi-parallel as though they were separate processes.

A thread sometimes called a lightweight process (LWP), is a basic unit of CPU utilization, it comprises a thread ID, a program counter, a register set, and a stack. It shares with other threads belonging to the same process it’s code section, data section, and other operating system resources, such as open files and signals.

A heavyweight (or traditional) process has a single thread of control. If the process has multiple threads of control, it can do more than one task at a time. The difference between a traditional single-threaded process and a multithreaded process is shown in fig 1.

Many software packages that run on modern desktop PC’s are multithreaded. an application typically is implemented as a separate process with several threads of control. For example, a web browser might have one thread for display image or text while another thread for retrieve data from the network.

A word processor may have a thread for displaying graphics, another thread for reading keystrokes from the user, and a third thread for performing spelling and grammar checking in the background.

threadvssingleprocess

Different threads in a process are not quite as independent as different processes. All threads have exactly the same address space, which means they also share the same global variables. Since every thread can access every memory address within the process address space, one thread can read, write, or even completely wipe out another thread’s stack.

There is no protection between the threads because (1) it is impossible and (2) it should not be necessary. Different processes, which may be from different users and which may be hostile to one another, a process is always owned by a single user, who has presumably created multiple threads so that they can cooperate.

In addition to sharing an address space, all the threads share the same set of open files, child processes, alarms, and signals, etc. as shown in fig2.

The item in the first column are process properties, not thread properties

threadcontent

Like a traditional process, a thread can be in any one of the several states running, blocked, ready or terminated. A thread which currently has CPU is called active, A blocked thread is waiting for some event to unblock it.

In the case of any queries, you can write to us at a5theorys@gmail.com we will get back to you ASAP.

Hope! you would have enjoyed this post about thread vs traditional process.

Please feel free to give your important feedbacks in the comment section below.

Have a great time! Sayonara!