THREADS
PROCESS
A process is an independent program in execution. It has its
own memory space (address space) and system resources.
Isolation: Each process runs independently and in isolation
from others. If a process crashes, it does not directly affect
other processes.
Heavyweight: Creating a process is more resource-intensive
because the operating system needs to allocate separate
memory and resources for each process.
PROCESS
Communication: Processes communicate with each other via
Inter-Process Communication (IPC) mechanisms like pipes,
message queues, shared memory, etc., which is slower
compared to threads.
Example: Running a web browser and a text editor
simultaneously involves two separate processes.
THREAD
A thread is a smaller unit of execution within a process.
Threads within the same process share the same memory
space and resources.
Lightweight: Creating threads is faster and requires fewer
resources compared to processes since they share the same
memory and system resources.
Shared Data: Threads within a process can easily share data
with each other because they have access to the same
memory space. However, this requires careful
synchronization to avoid conflicts (e.g., race conditions).
THREAD
Communication: Since threads share memory,
communication between threads is more efficient than
between processes.
Example: In a web browser process, multiple tabs can run as
separate threads within the same process.
KEY
DIFFERENCES
PROCESS - MEMORY THREAD - MEMORY
Has its own memory space Shares memory space with other threads in the
same process
KEY
DIFFERENCES
PROCESS - CREATION THREAD - CREATION
Expensive (resource-heavy) Lightweight (resource-light)
KEY
DIFFERENCES
PROCESS - COMMUNUCATION THREAD - COMMUNICATION
Uses IPC (Inter-Process Communication), slower Direct memory sharing, faster
KEY
DIFFERENCES
PROCESS - CRASH IMPACT THREAD - CRASH IMPACT
One process crashing won’t affect others A thread crash can affect the entire process
KEY
DIFFERENCES
PROCESS - EXECUTION THREAD - EXECUTION
Independent execution Concurrent execution within the same process
PROCESS EXAMPLE
Web Browser: When you open a web browser (e.g., Chrome
or Firefox), it runs as a separate process. Each tab might
also be treated as a separate process in modern browsers to
ensure that if one tab crashes, the rest of the browser
continues running smoothly.
Text Editor: Running a text editor like Microsoft Word or
Notepad opens a new process. This process runs
independently of other applications, and you can open
multiple instances (processes) of the text editor at once.
PROCESS EXAMPLE
Media Player: A video or music player (e.g., VLC Media
Player) runs as a process. You can open multiple instances
of this media player (each as a separate process), playing
different media files.
THREAD EXAMPLE
Web Browser Tabs: In a web browser, each tab within the
browser process may run as a separate thread. These
threads can handle tasks like loading web pages or
executing scripts concurrently, sharing memory like cookies
and session data.
Word Processor (Autosave): In a word processing
application (e.g., Microsoft Word), one thread might handle
the user interface while another thread periodically performs
an autosave operation in the background without
interrupting your typing.
THREAD EXAMPLE
Multiplayer Video Game: A multiplayer video game may
have multiple threads within one game process. For
example, one thread could handle rendering the graphics,
another thread could manage the network communication
with the game server, and yet another thread could manage
user input (e.g., keyboard and mouse controls).