Threads in Operating System
What is Threads in Operating System
There is a way of thread execution inside the process of any operating system. Apart from this, there can be more than one thread inside a process. Thread is often referred to as a lightweight process.
The process can be split down into so many threads. For example, in a browser, many tabs can be viewed as threads. MS Word uses many threads - formatting text from one thread, processing input from another thread, etc.
Properties of Thread
Here are important properties of Thread;
- Single system call can create more than one thread
- Threads share data and information.
- Threads shares instruction, global, and heap regions. However, it has its register and stack.
- Thread management consumes very few, or no system calls because of communication between threads that can be achieved using shared memory.
Types of Threads
In the operating system, there are two types of threads;
- Kernel level thread
- User-level thread
- The user-level threads are managed by users and the kernel is not aware of it.
- These threads are faster to create and manage.
- The kernel manages them as if it was a single-threaded process.
- It is implemented using user-level libraries and not by system calls. So, no call to the operating system is made when a thread switches the context.
- Each process has its own private thread table to keep the track of the threads.
- The kernel knows about the thread and is supported by the OS.
- The threads are created and implemented using system calls.
- The thread table is not present here for each process. The kernel has a thread table to keep the track of all the threads present in the system.
- Kernel-level threads are slower to create and manage as compared to user-level threads.
Components of Threads
Any thread has the following components;
- Thread ID
- Program counter
- Register set
- Stack space