let's identify the difference between both
[ Concurrency ]
Suppose multiple tasks are running, so they basically would start, run, and complete in overlapping time periods. You would feel like every task was running at the same time but that's not true.
E.g :
🔹Imagine that a cook is chopping salad while occasionally stirring the soup on the stove. He has to stop chopping, check the stove top, and then start chopping again, and repeat this process until everything is done. So there is a context switch happening.
🔹The only processing resource here is the chef. It looks like Chef is doing multiple things but in reality he is just doing one task at a time. If he doesn't do it concurrently, he has to wait until the soup on the stove is ready to chop the salad.
[ Parallelism ]
Parallelism is actually what its name suggests.
It's about multiple tasks or subtasks of the same task literally running at the same time on a hardware with multiple computing resources like a multi-core processor.
E.g :
🔹Extending the above example, assume you have two Chefs in the kitchen, now one who can do stirring and the other can chop the salad. So now both can literally do things in parallel at the same time. What have we done here? We’ve divided the work by having another processing resource, another chef.
----------------
Summary :
- Concurrency and Parallelism are strategies for managing and optimizing the execution of tasks in software systems.
- Concurrency is about structuring software to handle multiple tasks efficiently, even if they don't run in true parallel, while parallelism focuses on leveraging multiple processing units for faster execution.
- In modern computing, multi-core processors are prevalent, making parallelism an important consideration for optimizing performance.
Is it concurrent or parallel?
Difference between Concurrency and Parallelism | Concurrency vs Parallelism with example IN HINDI
Concurrency vs Parallelism
Concurrency vs Parallelism : Difference between them with examples & Comparison Chart