Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does erlang access shared resource?

Tags:

erlang

I am a new to erlang, and erlang is concurrency-oriented programming, it has no mutable data structures, that's why it's easy to parallelize.

But anyway, shared resource is still existed, for example, writing to same file. in this case, how does erlang synchronize accessing the shared resource between two processes?

like image 792
Chang Avatar asked Dec 27 '10 06:12

Chang


1 Answers

Typically what you might do is have one process responsible for access to the shared resource. Other processes would send messages to the single manager process for requests to read or write information to the shared resource.

Some shared resources (eg. some types of ETS tables) can be read by multiple processes but only one process can write to it. So you could set up one process to serialise writes to the table but let anybody read from it.

like image 110
Greg Hewgill Avatar answered Sep 22 '22 05:09

Greg Hewgill