On Mon, 2007-10-22 at 12:09 +0200, Erik Trulsson wrote:

> My own conclusion from this discussion (and others) is that shared memory is
> a lousy paradigm for communication between different threads of execution,
> precisely because it is so hard to specify exactly what should happen or not
> happen in various situations. 

in the abstract, this isn't really the case. Exactly the same problems
occur with message passing as with shared memory, for the trivial
reason that you can view memory reads as sending an address as
a message followed by a reply of the data (smly for writes).

The theorists working on message passing have great fun with
algorithms to ensure proper ordering .. which is just the
same problem as cache synchronisation.

The real difference is scoping: with shared memory it is
easy to accidentally fail to synchronise, but synchronisation
is easy. With processes and message passing, simple jobs
are trivial and all the communication is explicit, but for
complex interactions it is a lot of work and also 
can be extremely inefficient.

the big advantage of processes and message passing is the
potential to scale to the whole universe, whereas shared
memory abstracted across networks is likely to be
extremely slow and hard to reason about even if someone
actually implemented it.

Just as an example, Erlang is dynamically typed, purely
functional, and uses processes and message passing with
no ordering guarantees .. however it allows you to read
messages out of order. What this means is if you want
to synchronise .. you have to write code to actually do
it, eg a double handshake... shared memory systems
do that kind of thing directly in hardware, so you can
sometime work at a much higher level.



-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

Reply via email to