vitor_almeida

vitor_almeida

Does using Elixir make me understand less about concurrency?

Hello people.

I have only recently been studying Elixir and I hear about how simple it is to work with concurrency in the language. Does this mean that we don’t have to deal with race conditions, deadlocks and other problems? Doesn’t that make me know less about concurrency ?

Most Liked

ityonemo

ityonemo

Race conditions: no. There is nothing that can guard you against race conditions. I would say that vm startup race conditions bite me in the butt once every few months (but I’m really good at recognizing them now, and they are easy to fix in elixir).

Deadlocks: It’s rather hard to write a deadlock in elixir. At least genserver will keep you from writing a call from a process to itself. You could deadlock by calling a process that calls back, but that’s maybe a sign of poor systems design… So I can totally see a noob, especially from oop-land doing this.

Honestly, if anything you’ll get much better at writing correct concurrency patterns because a lot of the boilerplate will be pushed out of the way freeing you to think about the truly hard things like consistency, resiliency, and fault tolerance. In most other concurrent-capable PLs, I’m so exhausted with boilerplate that I can’t bother to think about those issues.

Recently I started implementing code in multithreaded zig and I realized that having worked in elixir “doing the right thing” just came naturally.

wanton7

wanton7

Elixir uses Erlang VM called BEAM uses processes (actors) that communicate with other processes by message passing and I’ll be calling them actors in rest of this answer.

You can still get race conditions

  1. actor1 keeps state
  2. actor2 and actor3 send message to actor1 that changes state at “same” time
  3. actor4 ask actor1 for state and that state could be state set by actor2 or actor3

But all in all in Elixir’s actor model it’s much simpler to reason about and you don’t usually have same kind concurrency problems you have in other languages. Because actor is running “single threaded” from programmers point of view and have their own memory that other actors can’t access. They communicate with other actors by sending them messages.

So you are still thinking about it but differently.

dimitarvp

dimitarvp

Not really IMO. It does give you a parallelism / concurrency model to think in that not many other languages support.

Last Post!

OvermindDL1

OvermindDL1

For general race conditions there is nothing that can catch all cases, however languages like Rust do make things like data race conditions impossible. :slight_smile:

Where Next?

Popular in Chat/Questions Top

rafaellcustodio
Hi sasajuric, any chance of a fresh promo code? :sunglasses:
New
Fl4m3Ph03n1x
I am doing some exercises while learning Elixir using Exercism.io. Now, my objective is to do all exercises, extras included. This shoul...
New
wallyfoo
Long story short, I have a real world need to create a view for hooking up a shipping terminal to live data, but because of some early ar...
New
zeroexcuses
Besides https://elixir-lang.org/getting-started/basic-types.html are there any other well recommended “elixir by example” style resources...
New
shansiddiqui94
Hello all, I recently did my first app in Phoenix and Liveview, many thanks to all the users who assisted me. I found that the tutorial ...
New
jace
I wanted to write a library for interacting with a Web API as a practical way of learning Elixir. However, there seem to be a lot of diff...
New
ariandanim
Hello all, I am still learning Elixir, then go into Phoenix, i am try search in google but find the programming phoenix 1.4, another for...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement