Understanding Processes, Threads, Concurrency, and Process Pools
This article explains the concepts of processes and threads, their differences, interaction methods, the three execution states of a task, synchronous and asynchronous communication, and the design and benefits of using a process pool to manage resources efficiently.
Process and Thread
1. Process
A process is an instance of a program that has been loaded into memory and is being executed; it is the smallest unit of resource allocation.
Key point: When a program runs, the running instance is called a process.
Process is a memory allocation unit that holds data and is the minimal resource management unit.
Processes act as containers for threads.
Difference between Program and Process
Program: a static collection of data and instructions stored on disk.
Process: a dynamic execution of a program with a lifecycle; it disappears when the program ends.
Process Interaction
Processes communicate via TCP/IP ports.
2. Thread
A thread is the smallest unit of execution that the operating system can schedule.
It resides within a process and represents the actual execution unit of that process.
Multiple threads can run concurrently within the same process, each with its own control flow.
A thread is a pipeline of a process that executes code without requesting additional resources; it is the smallest execution unit.
Thread Interaction
Threads share the same memory space and interact through shared memory.
3. Relationship Between Process and Thread
Example: Opening a chat application starts a process; opening features like "Space" or "Scan" creates threads within that process.
Thus, a process contains threads; threads are subsets of a process.
Parallelism, Concurrency, and Serial Execution
Concurrency: tasks appear to run simultaneously (pseudo‑parallelism).
Implemented on a single core using multitasking techniques.
Parallelism: multiple tasks truly run at the same time, requiring multiple cores.
Serial execution runs one task to completion before starting the next.
Task Execution States
A running process cycles through three states: Ready, Running, and Blocked.
Ready (Ready)
All resources except CPU are allocated; the process awaits CPU time.
Ready processes are placed in a ready queue.
Running (Running)
The process has obtained CPU time and is executing.
On a single‑core OS only one process runs; on multi‑core systems multiple can run.
Blocked (Blocked / Sleep)
The process is waiting for an event (e.g., I/O) and loses CPU time.
Blocking reasons include I/O wait or higher‑priority tasks preempting the CPU.
State Transitions
Processes move between these states repeatedly during execution.
Task Submission Methods
1. Synchronous
The sender waits for a response before sending the next data packet.
Two programs are interdependent; one thread blocks until the other finishes.
2. Asynchronous
The sender does not wait for a response before sending the next packet.
Threads operate independently of each other.
Process Pool
1. What Is a Process Pool?
A process pool consists of resource processes and management processes that reuse a fixed number of processes to handle tasks.
2. Why Use a Process Pool?
Creating and destroying processes for each task is costly; a pool limits the number of active processes, reduces scheduling overhead, and achieves concurrency.
3. Process Pool Concept
Define a pool with a fixed number of processes.
When a task arrives, an idle process from the pool handles it.
After completion, the process returns to the pool instead of terminating.
If all pool processes are busy, new tasks wait for a free process.
The pool size caps the maximum concurrent processes, simplifying OS scheduling and improving efficiency.
4. Resource Process
Pre‑created idle processes that the management process dispatches to handle work.
5. Management Process
Creates resource processes, assigns tasks, and recycles completed processes.
Interaction Between Resource and Management Processes
Management processes use IPC mechanisms such as signals, semaphores, message queues, and pipes to allocate tasks to resource processes.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.