A few of the advantages associated with threads are:
Parallelism:
It is nothing but executing more than one task at a time and so threads help in achieving parallelism. In the case of a multiprocessor, each thread can be executed independently by a different processor at the same time.
Responsiveness:
It adds more responsiveness to the system; if one thread is blocked, the other thread can continue to work but in the case of process, if the process is blocked the CPU goes to an idle state.
Economical:
Threads are more economical than processes in terms of creation, termination, and context switching as all threads share the same address space that is page table, signal table, open file descriptors are common among threads.
Inter-Process Communication(IPC):
IPC among threads are cheaper as all the threads share the same address space that is they share the common memory
Some of the disadvantages associated with threads are:
Robustness:
Thread-based application is less robust in comparison to process if something goes wrong even with a single thread-like memory access violation, it affects and corrupts all the threads as all threads share the common memory. This scenario leads to termination of the process abnormally.
Secure:
Threads based applications are not as secure as that of the process since all the threads share the common memory and can read and modify the shared memory easily.
Synchronization:
Thread based application has synchronization overhead since all the threads share the common memory and can read and modify the shared memory easily. Hence explicit synchronization mechanism like mutex, a semaphore is needed.
Debuggability:
Debugging a multithreaded program is difficult than a single threaded process.
Relevant Posts:
- Thread Introduction
- Types of Thread: User-Level and Kernel Threads
- Memory layout of Thread
- Thread Control Block(TCB)
- Characteristics of a Thread
- Process Vs Thread
- Thread Programming
Categories: Operating system (OS)
Leave a Reply