A thread is basically a flow of execution through the process code it has its own program counter stack and system registers. Thread is known as basic unit of CPU utilization. Threads improves the application’s performance by providing the facility of parallelism. They enhance they operating system’s performance by reducing the overhead thread is equivalent to a classical process. Threads cannot exist outside the process and each thread belongs to exactly one process. Each and every thread indicates separate flow of control. These days’ threads are also implementing in network and web servers. Threads provide a proper foundation for concurrent execution of applications on shared memory multiprocessors.
A single application can have multiple threads. Thread and process are different because process is resource intensive or heavy weighted while thread is light weight and consume less resources. Multiple processes required more resources in case if they never use the thread while multiple threads need fewer resources.
Advantages of Threads
- Decrease time for context switching.
- Provide efficiency in communication.
- Provide the facility of concurrency within a process.
Types of Threads
There are two methods to implement the thread
- User level thread: These threads managed by user. In this case, application manages thread management kernel is not responsive of the presence of The thread library holds code for creating and destroying thread, for passing message and data b/w threads, for scheduling thread execution and for restoring and saving thread contexts. The application commences with a single thread and starts running in that thread. Advertisement
- Kernel mode privileges are not required by thread switching.
- These threads can run on any operating system.
- Most system calls are blocking in a typical operating system.
- Multithreaded application cannot take benefit of multiprocessing
Kernel level thread: Threads that are acting on kernel managed by operating system. here is no thread management code in the area of application. Kernel threads are sustained directly by the operating system. All the application can be programmed to be multithreaded. All threads within an application are supported in one process.
- Kernel routines can be multithreaded by themselves
- The Kernel can schedule another thread of the same process, in case if a thread in a process is blocked
- Usually slower to create and manage.
- Transfer of control from one thread to another inside the same process requires a mode
switch to the Kernel.
|User Level Thread||Kernel Level Thread|
|Faster to manage and create||Slower to manage and create|
|Thread library use for implementation||O.S supports creation of kernel level threads|
|These are generic thread||These are specific to the O.S|