Single threaded processes contain the execution of instructions in a single sequence. In other words, one command is processes at a time.
The opposite of single threaded processes are multithreaded processes. These processes allow the execution of multiple parts of a program at the same time. These are lightweight processes available within the process.
Multithreaded Processes Implementation
Multithreaded processes can be implemented as user-level threads or kernel-level threads. Details about these are provided using the following diagram:
- User-level Threads
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. Also, there is no kernel involvement in synchronization for user-level threads.
- Kernel-level Threads
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.
Advantages of Multithreaded Processes
Some of the advantages of multithreaded processes are given as follows:
- All the threads of a process share its resources such as memory, data, files etc. A single application can have different threads within the same address space using resource sharing.
- It is more economical to use threads as they share the process resources. Comparatively, it is more expensive and time consuming to create processes as they require more memory and resources.
- Program responsiveness allows a program to run even if part of it is blocked using multithreading. This can also be done if the process is performing a lengthy operation.
- In a multiprocessor architecture, each thread can run on a different processor in parallel using multithreading. This increases concurrency of the system. This is in direct contrast to a single processor system, where only one process or thread can run on a processor at a time.
Disadvantages of Multithreaded Processes
Some of the disadvantages of multithreaded processes are given as follows:
- Multithreaded processes are quite complicated. Coding for these can only be handled by expert programmers.
- It is difficult to handle concurrency in multithreaded processes. This may lead to complications and future problems.
- Identification and correction of errors is much more difficult in multithreaded processes as compared to single threaded processes.