Chapter 3. Processes 101

 

This chapter covers

  • The Actor concurrency model
  • Creating processes
  • How to send and receive messages using processes
  • Achieving concurrency using processes
  • How to make processes communicate with each other

The concept of Elixir processes is one of the most important to understand, and it rightly deserves its own chapter. Processes are the fundamental units of concurrency in Elixir. In fact, the Erlang VM supports up to 134 million (!) processes,[1] which would cause all of your CPUs to happily light up. (I always get a warm, fuzzy feeling when I know I’m getting my money’s worth from my hardware.) The processes created by the Erlang VM are independent of the operating system; they’re lighter weight and take mere microseconds to create.[2]

2 Joe Armstrong, “Concurrency Oriented Programming in Erlang,” Feb. 17, 2003, http://mng.bz/uT4q.

We’re going to embark on a fun project. In this chapter, you’ll build a simple program that reports the temperature of a given city/state/country. But first, let’s learn about the Actor concurrency model.

3.1. Actor concurrency model

Erlang (and therefore Elixir) uses the Actor concurrency model. This means the following:

3.2. Building a weather application

3.3. The worker

3.4. Creating processes for concurrency

3.5. Collecting and manipulating results with another actor

3.6. Exercises

3.7. Summary

sitemap