<div dir="ltr">By "resource" I meas the state in processes. Such as the State in gen_server or gen_fsm.<div><br></div><div>I think Fred's method is good if performance really matters. Though it is a little tricky.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-04-15 22:28 GMT+08:00 Aidan Hobson Sayers <span dir="ltr"><<a href="mailto:aidanhs@cantab.net" target="_blank">aidanhs@cantab.net</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I think you need to clarify what kind of resource you're talking about.<div><div>E.g. multiple read operations on a flat file doesn't need locks, but you physically cannot read it in concurrently. You have to have some way of coordinating, be it by locking or letting the kernel do it.</div>


</div><div>The details of the answer change depending on what specifically you're trying to do. But in short, there's very likely a way to do what you want.</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra">
<br><br><div class="gmail_quote">

On 15 April 2014 14:46, Bin Wang <span dir="ltr"><<a href="mailto:wbin00@gmail.com" target="_blank">wbin00@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div dir="ltr">I meas if there is a write, then give it a lock. If all the requests are read operations, then no lock is needed. That means multiple read operations could be doing at the same time while there is no write operations.<div>



<br></div><div>However, in actor model, the requests are always handled one by one no matter they are reads or writes. So didn't it slow at some situations? (Read are more that write).</div><div><br></div><div>---</div>



<div>Bin Wang</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-04-15 21:37 GMT+08:00 Dmitry Kolesnikov <span dir="ltr"><<a href="mailto:dmitry@evoqu.com" target="_blank">dmitry@evoqu.com</a>></span>:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
No, this is not good.<br>
<br>
Any on-going “write request” makes changes to the state. The read request does not know when the state becomes consistent unless there is a lock on the state. You cannot ensure safe reading while writes is going on. Therefore, actor model has bigger advantage.<br>




<br>
- Dmitry<div><div><br>
<div><div><br>
On 15 Apr 2014, at 16:31, Bin Wang <<a href="mailto:wbin00@gmail.com" target="_blank">wbin00@gmail.com</a>> wrote:<br>
<br>
> In Erlang, we handle concurrency in such a way: a process receives messages in its mailbox. And handle them one by one, just one in the same time.<br>
><br>
> But in some situation, the request just want to read the resource. So the read requests should be able to execute at the same time since they don't change or break anything.<br>
><br>
> So dose this meas if we use a write lock in such situation, we will have a better performance? If so, does Erlang have a proper way to do that?<br>
><br>
> Thanks.<br>
><br>
> ---<br>
> Bin Wang<br>
</div></div></div></div>> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
</blockquote></div><br></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>