[erlang-questions] Question about message passing paradigm
Richard A. O'Keefe
Tue Jul 1 06:48:35 CEST 2008
On 1 Jul 2008, at 3:42 pm, Edwin Fine wrote:
> I'm new to Erlang and FP, and I want to learn from my mistakes or
> misunderstandings. Please could you critique the suggestion I sent
> in regarding this problem? The fact that nobody commented means
> either that it was (a) totally naive and not worthy of comment (or
> to spare my feelings), or (b) such a good idea that all were
> rendered speechless with admiration. Somehow the probability of (b)
> seems rather low. So... where did I go wrong?
Let's recapitulate. If I've found the right message,
Edwin Fine had three suggestions:
• Create a gen_fsm that controls all the collections.
The collections could be ETS tables or gen_servers wrapping ETS
Under normal use, messages are sent to the fsm to update the
individually. When the time comes to require consistency across the
collections, send a message to the fsm to get the collective state
The fsm goes into a different state while it gathers the data.
This state would reject requests to update the collections (or wait
the state changes), although reads would still be allowed.
On getting the result, the state changes back to allow updates again.
• Create a memory-only Mnesia table for each collection, and use Mnesia
transactions to get the multiple values atomically.
• Change the architecture of the current lock-oriented program to make
better use of Erlang's features.
From bottom to top:
- The last one doesn't really answer the orignal poster's question.
At least, imagining myself in the OP's shoes, I would not find that
answer informative. Change it HOW? WHICH features? In what way
- The second one might well be the right thing to do in a production
system. However, someone who is still struggling with how to use
probably doesn't want to be told to learn another huge great
might well get the impression that message passing wasn't much good
- As for the first one, it seemed to me that in order to do that,
pretty much have to solve the original problem anyway, plus you
have to come to grips with behaviours, callbacks, gen_fsm, and a
stuff which is practically very very useful, but not something to be
understood in five minutes.
I suppose I can summarise it as "You gave OTP answers to what I saw as
an Erlang question". I may well be completely mistaken about where the
OP was coming from, but I understood the question to be specifically a
question "how can the OP solve this problem directly using message
OTP answers are very often precisely the right answers, so don't stop
More information about the erlang-questions