Skip to main content

Process vs threads; importance in DS

Short answer

A process has its own address space and resources; a thread shares its process's address space, making creation and switching cheap. Threads are crucial in distributed systems for multithreaded servers handling concurrent clients, hiding network latency (e.g., web browser fetching images while rendering), and overlapping I/o and computation to improve scalability.

Define and differentiate between process and threads. Explain the importance of threads in distributed system with suitable examples.

Process and thread

  • A process is a program in execution with its own address space (code, data, heap), resources (open files) and at least one thread of control.
  • A thread is a lightweight unit of execution inside a process. It has its own program counter, registers and stack, but shares the address space, data and open files of its process.
PointProcessThread
Address spaceOwn, protectedShared with other threads of the process
Creation / switch costHighLow
CommunicationNeeds IPC (pipes, messages)Direct through shared memory
ProtectionStrong isolationNone between threads
FailureOne process does not affect anotherA faulty thread can crash the process
ResourcesOwn setShare process resources
Also calledHeavyweight processLightweight process

Importance of threads in distributed systems

  1. Multithreaded servers: a server handles many client requests at once. One dispatcher thread takes requests and worker threads process them, so a slow request (disk or network wait) does not block others. Example: a web server creates a thread per request, a file server serves many clients.
  2. Hiding latency in clients: a web browser uses one thread to fetch the page while others fetch images and render, so the user is not blocked on network delay.
  3. Overlap of computation and I/O, which improves performance and throughput, and makes use of multiprocessors.
  4. Cheap communication and switching: shared memory between threads is more efficient than between processes.
  5. Simpler program structure: blocking system calls (RPC, RMI) can be used in each thread while the program continues in others.
  6. Better scalability as a server handles more clients per machine.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Distributed System chapter 3 questions →