operating-systems

Definition

Thread

A thread (or execution string) is the smallest unit of execution within a process. While a process provides the execution environment and owns the resources, a thread is the unit of dispatching—the entity that the OS scheduler assigns to a CPU for execution. Individual threads within a process share the same address space and resources but maintain their own program counter and stack.

Threads are often called “lightweight processes” because they are easier to create and manage than full processes.

Process vs. Thread

A process can contain multiple threads that share the same address space and resources, but each thread has its own program counter, stack, and register set.

FeatureProcessThread
Resource OwnershipOwns its own memory space and resources.Shares the resources of its parent process.
IsolationHigh isolation; crashing one process doesn’t affect others.Low isolation; one thread’s crash can affect the entire process.
OverheadHigh creation and switching cost.Low creation and switching cost.
CommunicationRequires complex IPC (Inter-Process Communication).Can communicate easily via shared memory.

Benefits

  • Responsiveness: A multi-threaded application can remain responsive to input while performing background tasks.
  • Parallelism: On multi-core systems, different threads of the same process can run truly simultaneously.
  • Efficiency: Creating a thread is much faster than creating a full process because the OS does not need to allocate a new address space.