Advantages and Disavantages of Threads

Threads have a lot many advantages and a disadvantage as well. The article tries to outline the advantages and disadvantages of using threads in Linux.

ADVANTAGES

  • Parallelism and blocking I/O – With Most multi-core systems, threads provide a means of achieving parallelism. If a particular thread is waiting for I/O, another thread can still continue another portion of work on a parallel core.
  • Process Responsiveness – It can improve process responsiveness. Multiple threads can be assigned with different tasks and one task getting stuck will still still allow threads on other tasks to proceed further.
  • Memory utilization – All threads share the same memory block of the process. Hence, Threads provide a means of saving on memory. Starting Multiple processes to accomplish different tasks that a particular process wishes to perform would result in multiple memory blocks being utilized by the different processes. 
  • Context switching is less intensive in threads than in processes – When context switch needs to occur between different threads, the program counter, stack and registers are switched. The virtual memory is the same and does not need to be changed. When a process needs to be switched, the Translation lookaside buffer (TLB) of the processor gets cleared which results in more time being spent on Memory accesses. Hence, Process context switching is a bit more intensive than thread context switching.
  • Information sharing – Sharing of information between threads is way faster than a process since threads share the same memory space. Processes need to implement inter-process communication mechanisms to communicate between one process to another

DISADVANTAGE

  • Memory management between threads – Since different threads share the same virtual memory space, multiple threads can contend to access a particular memory region or block. Suitable locking and synchronization measures must be taken to prevent different threads from dead-locking. 

Posix Threads – An Introduction

Comments

  1. Pingback: What is Multi-threading? | Hitch Hiker's Guide to Learning

  2. vivekananda holla

    If any reader is aware of further thread problems – please share it in the comment

Leave a Reply

Your email address will not be published. Required fields are marked *