Meyer, OO and concurrency

Ulf Wiger ulf@REDACTED
Thu Jul 14 02:02:07 CEST 2005


Den 2005-07-14 00:47:11 skrev Richard A. O'Keefe <ok@REDACTED>:

> Even Erlang has the shameful process dictionary, but at least process
> dictionaries are private and cannot be modified by any other process.

(Mainly for the lurkers and beginners on the list)

I've argued before that I think process dictionaries have received
a bad reputation unjustly. They have the same basic semantics as
private ets tables, but have some nice advantages besides the obvious
advantage of convenience.

Attached is an incomplete (and inefficient) implementation of a process
dictionary, written in plain erlang. The inefficiency comes mainly
 from the very naiive choice of access structures in the program,
not from the message passing (unless the key-value pairs are big
and we're not using shared or hybrid heap.)

There's nothing in the process dictionary that can't be implemented
with same semantics in plain erlang, using a registered process and
some message passing.

9> c(procdict).
{ok,procdict}
10> procdict:start().
<0.67.0>
11> procdict:put(a,17).
undefined
12> procdict:get(a).
17
13> procdict:get().
[{a,17}]
14> procdict:get(b).
undefined
15> procdict:put(a,147).
17


One might argue that it's wrong to make it so convenient
and efficient to use something like a process dictionary.
Of course, if the process communication can be made
arbitrarily fast, you can easily implement destructive
assignment of global variables in Erlang -- process
dictionary or no process dictionary. The culprit is the !
operator. ;-)

/Uffe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: procdict.erl
Type: application/octet-stream
Size: 2078 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20050714/d30a7301/attachment.obj>


More information about the erlang-questions mailing list