What is a thread in the operating system with an example?& how are these different from the traditional process?

Hello Friends, In this blog post(What is a thread in the operating system with an example) 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.

Inside this blog(What is a thread in the operating system with an example), we will explore What is a thread in the operating system with an example? What are the thread and processes? What are the states of thread in OS?

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|What is a thread in the operating system with an example|

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|What is a thread in the operating system with an example|

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.

Go through with some quick revision:

What is a thread in the operating system with an example?

There are two types of threads in the computer system. One is a user thread that does not deal with the operating system. And executed over kernel threads. User thread is very fast and efficient and more than one threads can be executed concurrently. For example, MS word where user threads run the program and process to work with this application.

Kernel threads work within the OS. And it looks at all the activities inside the operating system and supports the multiple threads and system calls.

What are the thread and processes?

A program in execution is called a process. Inside a process, there may be one and more threads running to complete the process. The thread can be considered the smallest unit to which OS assigns the processor time. A thread can run any part or code of a process.

What are the states of thread in OS?

We can have any number of threads inside an executing process. Threads have states like NEW, RUNNABLE, BLOCKED, TERMINATED.

In the case of any queries, you can write to us at [email protected] we will get back to you ASAP.

Hope! you would have enjoyed this post What is a thread in the operating system with an example.

Please feel free to give your important feedbacks in the comment section below|What is a thread in the operating system with an example|

Have a great time! Sayonara!

Anurag

I am a blogger by passion, a software engineer by profession, a singer by consideration and rest of things that I do is for my destination.