What's it called when multiple threads execute at the same time? Parallelism? Concurrency? 🤔 Is there a difference? (Spoiler: Yes!) Let me explain in a few tweets, ripping off @pressron's #InsideJava blog post "On Parallelism and Concurrency". 🧵 inside.java/2021/11/30/on-…
Parallelism: Taking a task and splitting it up, so multiple CPUs can compute partial solutions in parallel to solve the task in less wall-clock time. Concurrency: Having a number of tasks that need to be arranged in a way that solves as many of them per $time_unit as possible.
Some parallelizable tasks: * sorting an array * inverting a matrix * rendering graphics Some examples for concurrency: * processing incoming web requests * making outbound calls to DB and/or other web services * observe file system for changes
Parallel and concurrent problems have a lot in common, but also a number of distinctive properties: * task origin and control * resource use and coordination * main metric * use and number of threads Let's juxtapose them.