A thread is a lightweight process that can be managed independently by a scheduler. It improves the application performance using parallelism.
A thread shares information like data segment, code segment files etc. with its peer threads while it contains its own registers, stack, counter etc.
The two main types of threads are user-level threads and kernel-level threads. A diagram that demonstrates these is as follows −
The user-level threads are implemented by users and the kernel is not aware of the existence of these threads. It handles them as if they were single-threaded processes. User-level threads are small and much faster than kernel level threads. They are represented by a program counter(PC), stack, registers and a small process control block. Also, there is no kernel involvement in synchronization for user-level threads.
Some of the advantages of user-level threads are as follows −
Some of the disadvantages of user-level threads are as follows −
Kernel-level threads are handled by the operating system directly and the thread management is done by the kernel. The context information for the process as well as the process threads is all managed by the kernel. Because of this, kernel-level threads are slower than user-level threads.
Some of the advantages of kernel-level threads are as follows −
Some of the disadvantages of kernel-level threads are as follows −