What: A program is a static set of instructions written in a programming language (like Kotlin, Java, or Python) that defines what actions a computer should perform.
Why: Programs provide a blueprint for a computer to execute a specific task or solve a problem.
How: The operating system loads a program into memory, converts it into one or more processes, and begins execution.
What: A process is a running instance of a program. It has its own process ID (PID), state, memory space, network handles, and file system handles.
Why: Processes allow programs to execute independently, each with its own memory and resources, preventing interference between applications.
How: When you run a program, the operating system creates a process for it and allocates memory and resources to handle execution.
What: A thread is the smallest unit of execution within a process. Every process has at least one thread — called the main thread or thread of execution.
Why: Threads allow a program to perform multiple tasks simultaneously (e.g., downloading a file while updating the UI).
How: A process can create multiple threads, and all threads share the same memory space but run independently on different CPU cores (if available).
What: In sequential execution, instructions are executed one after another — one task must finish before the next begins.
Why: This is simple and predictable but inefficient when tasks can be run concurrently (like waiting for network responses).
How: The CPU executes each instruction in order, using a single thread without parallelism or concurrency.
What: A thread pool is a collection of pre-created threads that can be reused to execute multiple tasks concurrently.
Why: Creating new threads is expensive in terms of system memory and CPU time. A thread pool reduces overhead by reusing existing threads instead of creating new ones for every task.
How: When a task is submitted, a thread from the pool picks it up and executes it. After completion, the thread returns to the pool for reuse. This is used heavily in frameworks like Executors in Java and Dispatchers.IO in Kotlin coroutines.
What: A coroutine is a lightweight, cooperative unit of work that can run multiple tasks on the same thread without blocking it.
Why: Threads have system-level limitations — each thread consumes memory and CPU context. Coroutines are user-level constructs that can handle thousands of tasks efficiently without creating thousands of threads.
How: Coroutines use suspension instead of blocking. When a coroutine waits (e.g., for a network call), it suspends itself and lets another coroutine run on the same thread, resuming later when the result is ready.
Co means cooperative and routines means functions. Together, coroutines are cooperative functions that work together efficiently by yielding control when waiting for a result instead of blocking the thread.