Concurrency vs Parallelism vs Async vs Multithreading
Explore why Concurrency and Parallelism are essential concepts and how techniques like Async and Multithreading are used to achieve efficient task management.
Intro #
Let’s figure out why we need these terms and what they actually mean.
Classification #
Before diving into details, we need to classify our terms. Do Concurrency, Parallelism, Async, and Multithreading belong to the same group?
We can split these terms into two groups: concepts and techniques.
Concepts and techniques are like categories and items in real life. For instance, we have the category “fruits” and an item in this category, like an apple.
In this case, Concurrency and Parallelism are concepts. Async and Multithreading are concrete techniques.
Concepts definitions #
Concurrency #
In simple terms, concurrency means a program can handle many tasks at the same time. The user doesn’t have to wait for one task to finish before starting another.
To understand this better, let’s look at a real-life example.
Imagine you have an old iPhone, like the iPhone 4. On that iPhone, you have the App Store, which lets you download and update apps. If you open the store and press the download button on an app (like the Calculator app), then switch to another tab to check details for a different app, you will notice that the app doesn’t freeze. It continues downloading the first app while you browse others. This smooth behavior is a practical example of concurrency in action.
The interesting part is how this works behind the scenes.
In our example, the app (App Store or Play Store) is doing two tasks at once: downloading a file and showing information about another app. This is possible because the system quickly switches between tasks, creating the illusion of parallel execution.
You might wonder, “Why do we need the illusion of parallel execution?” That’s because the iPhone 4 has a single-core CPU that does not allow for real parallel execution. To implement real execution, we need a device with a multi-core CPU (like the iPhone 4s or higher). Multi-core CPUs allow us to achieve real parallel execution. The concept of Concurrency with real parallel execution is known as Parallelism.
Parallelism #
Now that we understand concurrency, let’s talk about parallelism!
While concurrency involves managing multiple tasks by switching between them, parallelism involves performing multiple tasks at the same exact time. That’s the key difference.
Let’s return to our iPhone example.
Suppose you upgrade from an iPhone 4 to an iPhone 16 Pro, which has a multi-core processor. This means it has multiple cores inside the CPU, not just one. So when you download the Calculator app and browse the App Store at the same time, the phone actually performs both tasks simultaneously using different cores.
Let’s consider another example. Imagine you’re in a kitchen. If you’re alone and need to boil water and make a sandwich, you might start the water, then prepare the sandwich while it heats up. That’s concurrency — you’re juggling tasks.
But if you have a friend helping — one person boils the water while the other makes the sandwich — now you’re genuinely doing both tasks at the same time. That’s parallelism.
Parallelism is only possible when the hardware supports it, usually through multiple CPU cores. Each core can handle a separate task independently and simultaneously. This is powerful, especially for performance-heavy apps like games, video editing tools, or large-scale data processing.
To summarize:
Concurrency is when your system manages multiple tasks by quickly switching between them (even with one core). Parallelism is when your system handles multiple tasks simultaneously using multiple cores.
Techniques definitions #
Async (Asynchronous Programming) #
Async means a program can start a task and then move on to do other things without waiting for that task to finish. It’s like ordering a pizza and watching TV while waiting instead of standing around doing nothing.
Async helps programs stay busy and responsive, especially with slow tasks like downloading files or retrieving information from the internet.
Example: Imagine you’re using Spotify on your phone. You tap to download a new song, and while the song downloads, you can still browse your playlists, search for other music, or adjust the volume without the app freezing or slowing down. The download happens in the background, keeping the app smooth and responsive. That’s async in action.
How it works: Async uses tools like “promises” or “await” to start tasks in the background. The program continues to work and checks back later to see if the task is done. It’s like sending a message to a friend and getting back to work until they reply.
Multithreading #
Multithreading is when a program divides its work into smaller parts called “threads.” These threads run simultaneously, like many workers doing different jobs together.
Example: When you use a photo editor, one thread might save your work while another allows you to keep editing. Both actions happen at the same time because of multithreading.
How it works: #
Each thread is like a small worker inside the main program. If your computer has multiple cores, each thread can run on a different core at the same time. For example, a game might use one thread for graphics, another for sound, and another for player controls.
Key difference: #
Async means starting a task and moving on without waiting, usually on one core. Multithreading means running many tasks at the same time on different cores.
Summary #
- Async: Start a task, keep working, and check back later. Good for apps that need to stay fast, like a weather app loading data.
- Multithreading: Run many tasks at once using different threads and cores. Good for heavy work, like photo editing or gaming.
Hierarchy #
I hope this helps answer your questions and gives you a clearer picture of the differences between these terms. To sum it up, let’s finalize our article with a hierarchy of these terms.
Hierarchy:
- Concurrency
- Async
- Multithreading
- Parallelism