Introduction to Concurrency

Learn about the ways in which concurrency can be achieved and their subsequent advantages.

Multi-threading

Since the dawn of the computer industry, hardware manufacturers and computer scientists have tried to make computers faster at running programs. At first, multi-threading was the only way to achieve concurrency. Multi-threading is when we run two or more programming tasks and switch between them to collect the results. This is how computers appear to be doing many things at once—they are actually multitasking.

Multi-core CPUs

Multi-core CPUs brought parallelism and allowed tasks to run at the same time independently. This significantly increased systems’ performance. Multi-processor architectures followed that enabled even greater concurrency and parallelism by supporting two or more CPUs on a single machine. The figure below shows a simple comparison between concurrency on a single-core CPU and a dual-core CPU. The latter also enables parallelism.


Benefits of advancements

Cutting-edge hardware always comes with a high price tag. However, with the advent of cloud computing, things changed once again. Now, we can run code on cloud services using virtual machines with dozens of CPU cores, without the need to buy and maintain any physical hardware.

All these advancements are important to software engineers. We want to write software that performs well and runs quickly. After all, no one likes waiting for loading screens. However, running code on a multi-core processor system does not automatically make it efficient. To take full advantage of the computer resources, we need to write software with concurrency and parallelism in mind.

Thankfully, modern programming languages try to help us as much as possible, and Elixir is no exception. Thanks to Erlang, the Erlang Virtual Machine (BEAM), and the Open Telecom Platform (OTP), Elixir is a superb choice for building concurrent applications and processing data, which we’ll see soon in this and upcoming chapters.