Chang
Chang

Reputation: 4133

How does erlang access shared resource?

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?

Upvotes: 7

Views: 928

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 993243

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.

Upvotes: 11

Related Questions