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.

NobbZ

NobbZ

You have the same problems, though they are less common due to message passing and immutability.

mindriot

mindriot

In addition to the other points made, because the model for exchanging concurrent data is always explicit it is often the case that it is easier to see that a particular implementation will lead to race conditions or dead locks.

Where Next?

Popular in Chat/Questions Top

nur
https://e.planaria.network/stack.png https://e.planaria.network Build a NoSQL DB, Build a Relational SQL Database, Build a Graph Datab...
New
Iex.new
Hello!, I just started this week to discover Elixir. I’m a PHP-Programmer and did some sutff in Go too. The more I read about Elixir t...
New
Scoty
Hey, I am currently reading Programming Elixir and I am doing one of the exercises where you should write a solution to the “I’m thinkin...
New
RKC07
I’m new to elixir. I did some coding in python and C. I want to learn elixir for starting my career in web development. I need suggestion...
New
Allyedge
Hey, I want to learn Elixir OTP and I wanted to know if there are any good resources that teach it. I found some web pages, but none of t...
New
ericmachine88
Hi all, I am currently on this course Half a way thru, and struggled a bit… sometimes I don’t even know what I am coding especially ...
New
Kielo
Hi, I run a language learning blog and would like to learn how to code so I can create an app to help English speakers learn French. I ...
New
logesh
Could someone provide a learning path for functional programming for who came from oops background.? Thanks in advance
New
SavagePixie
I was wondering if there are any beginner-friendly, exercise-based resources for learning Elixir out there. I’m looking for something lik...
New
Fl4m3Ph03n1x
Background I am trying to do the typical Ceaser cypher exercise in Elixir. The description of the exercise is as follows: Create an impl...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
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

We're in Beta

About us Mission Statement