Revanth Vermareddy

Concurrency vs Parallelism

1 minutes (346 words)
concurrency-vs-parallelism-icon

Concurrency and parallelism are two terms that are often used in the context of multithreaded and multiprocess programming.

Here’s a brief explanation of each:

🔗Concurrency:

Concurrency is when two or more tasks can start, run, and complete in overlapping time periods. It doesn’t necessarily mean they’ll ever both be running at the same instant (e.g., multiple threads on a single-core machine). In Python, you can achieve concurrency through threading, asyncio, and other libraries. Concurrency is about dealing with a lot of things at once.

🔗Parallelism:

Parallelism is when tasks literally run at the same time, e.g., on a multicore processor. Parallelism is about doing a lot of things at once.


In the context of Python, due to the Global Interpreter Lock (GIL), Python threads are not truly parallel and are suitable for I/O-bound tasks. For CPU-bound tasks, you would use multiprocessing to achieve true parallelism, as each process gets its own interpreter and memory space, thus bypassing the GIL.

🔗Why does it matter?

Remember, while concurrency and parallelism can make your program faster and more responsive, they also add complexity to your program and can make it harder to reason about. It’s important to understand these concepts well and use them appropriately. 😊

Tags: #concurrency #parallelism