erlang如何访问共享资源?
我是 erlang 的新手,erlang 是面向并发的编程,它没有可变的数据结构,这就是为什么它很容易并行化。
但无论如何,共享资源仍然存在,例如写入同一个文件。在这种情况下,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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您可能会做的是让一个进程负责访问共享资源。其他进程将向单个管理器进程发送消息,以请求读取或写入信息到共享资源。
某些共享资源(例如某些类型的 ETS 表)可以由多个进程读取,但只有一个进程可以对其进行写入。因此,您可以设置一个进程来序列化对表的写入,但允许任何人从中读取。
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.