Demystifying Computing: Processes, Threads, and the Magic of Parallelism and Concurrency.

PrimerPy
4 min readNov 10, 2023

--

In the practice of software development and operating systems, the concepts of processes and threads are foundational to understanding how computers execute tasks efficiently. This article aims to demystify these terms and provide a clear understanding of their functions and how they contribute to the overall performance of computing systems.

Process vs. Thread

Process

In the realm of computing, a process can be likened to a program that is currently active and running on a computer system. Think of it as the living, breathing entity of software execution. The custodian of these processes is known as the Process Control Block (PCB), which keeps a watchful eye on their activities.

A process can also give birth to new processes, referred to as child processes. However, processes operate independently and do not share memory with one another.

A process has the following states:

Start: The starting point for a process. This is where the process begins.

Ready: In this phase, a process is basically waiting in line, hoping to get a turn to run on the computer’s processor. It’s like being in a queue, and the operating system decides who gets to go next.

Running: When the operating system picks a process to run (by the OS scheduler), it enters the running phase. This is when the processor starts following the instructions of the chosen process, like an actor on a stage.

Waiting: Sometimes, a process has to wait for something, like a file to become available. When that happens, it moves into the waiting phase until it gets what it needs.

Terminated: When a process finishes its job or the operating system decides to end it, it goes into the terminated phase. It hangs around for a bit before eventually leaving the computer’s memory.

Thread

Think of a thread as a mini-task inside a bigger job. It’s like different characters in a play, each playing a specific role within the overall story, which is the process. A thread is a section of a process and a process may contain many threads and these threads lies within the process. A thread has the following states:

  • Running: This is when a thread is actively doing its job.
  • Ready: Threads in this state are all dressed up and just waiting for their turn to take the stage.
  • Blocked: These threads are temporarily paused, as if they’re waiting for a crucial cue in the play.

Threads are quicker to get going compared to processes, but threads can share information with other threads. Processes, on the other hand, tend to keep everything separate.

Here’s a an example:

  • When you open Chrome on your computer, it’s like starting a new process. Think of it as setting up a dedicated workspace for your web browsing.
  • Within this Chrome process, you can open multiple tabs, which can be thought of as threads within the Chrome process. Each tab represents a specific task or webpage.
  • For instance, if you open Chrome and create three tabs, such as one for email, one for social media, and one for a news website, each of these tabs can be considered a separate thread within the Chrome process.
  • These threads (tabs) operate independently within the same Chrome process. They can switch between tasks (websites) quickly, and they share resources (memory, CPU, etc.) to help you browse the web efficiently.

So, when you open Chrome and multiple tabs, you have a single Chrome process as your web browsing “workspace,” and within that process, you have multiple threads (tabs) that work together to handle different web tasks while sharing the resources of the Chrome process.

Parallelism and Concurrency

Parallelism refers to the technique of running multiple calculations or processes simultaneously. It often involves breaking down a problem into several parts that can be solved concurrently, with each part running on a separate processor or computer. The main focus of parallelism is to increase the computational speed by performing multiple operations simultaneously.

Concurrency, on the other hand, is related to how an application handles multiple tasks it works on. It involves making progress on more than one task simultaneously and can be achieved even on a single-core processor by context switching. The main focus of concurrency is not to perform operations simultaneously, but to manage multiple tasks in a way that the user perceives them as happening at the same time, optimizing the use of resources.

Below is a comparison of these concepts:

To wrap things up, grasping the difference between processes and threads goes beyond theoretical knowledge — it’s about recognizing the gears that keep our software running smoothly. Parallelism and concurrency aren’t just buzzwords; they’re the core concepts that allow our apps and systems to operate seamlessly and stably. For those in the tech field, a solid understanding of these principles is more than beneficial — it’s critical. They’re the foundation of effective multitasking in operating systems and the sturdy framework behind server applications. As we navigate the ever-changing landscape of technology, the strategic implementation of processes and threads remains key, continually expanding the horizons of computing capabilities.

--

--

PrimerPy
PrimerPy

Written by PrimerPy

www.primerpy.com | A Primer on Python. I'm a veteran Data and Web developer based out of NYC and DC area. I blog mainly on Python and other tech related topics.

No responses yet