What's the difference between the message passing and shared memory concurrency models?

79,860

Solution 1

It's a pretty simple difference. In a shared memory model, multiple workers all operate on the same data. This opens up a lot of the concurrency issues that are common in parallel programming.

Message passing systems make workers communicate through a messaging system. Messages keep everyone seperated, so that workers cannot modify each other's data.

By analogy, lets say we are working with a team on a project together. In one model, we are all crowded around a table, with all of our papers and data layed out. We can only communicate by changing things on the table. We have to be careful not to all try to operate on the same piece of data at once, or it will get confusing and things will get mixed up.

In a message passing model, we all sit at our desks, with our own set of papers. When we want to, we can pass a paper to someone else as a "message", and that worker can now do what they want with it. We only ever have access to whatever we have in front of us, so we never have to worry that someone is going to reach over and change one of the numbers while we are in the middle of summing them up.

Ok, silly analogy!

Solution 2

  1. In shared memory model, memory is shared by cooperating processes, which can exchange information by reading and writing data but in message passing communication takes place by means of messages exchanged between the cooperating processes.
  2. Shared memory helps run processes concurrently but message passing cannot.
  3. Message passing facility has two operations: send (message) and receive (message). The process of which has fixed or variable size.
  4. Message passing is useful for exchanging smaller amounts of data, because no conflicts need be avoided. Message passing is also easier to implement than is shared memory for interprocess communication.
  5. In shared-memory systems, system calls are required only to establish shared-memory regions. Once shared memory is established, all accesses are treated as routine memory accesses, and no assistance from the kernel is required.

Faster

Shared memory allows maximum speed and convenience of communication, as it can be done at memory speeds when within a computer. Shared memory is faster than message passing, as message-passing systems are typically implemented using system calls and thus require the more time-consuming task of kernel intervention.

Solution 3

Message passing models (Erlang, for example) do not have any shared state; all synchronization and communication is done by exchanging messages. Shared memory models communicate by reading/writing to shared memory blocks, which are protected by semaphores or similar.

Solution 4

message passing are good method to justify data but it has slow response time for faster communication.But in shared memory model data are extracted from one memory and a working group can do different work over same data

Solution 5

Though you are asking for the differences between message-passing model and shared memory model and have already got good answers concerning about their performances, ways of exchanging information, and concurrency issues, I would like to point out that:

There can be no fundamental differences between them regarding their computability (under certain conditions).

You can simulate a shared memory over the underlying message-passing system. This makes it possible to view the shared memory model as a higher-level language for designing algorithms in asynchronous distributed message-passing systems.

In particular, this paper ABD@JACM'95 shows that

Any wait-free algorithm based on atomic, single-writer (and multi-writer) multi-reader registers can be automatically emulated in message-passing systems, provided that at least a majority of the processors are not faulty and remain connected. The overhead introduced by these emulations is polynomial in the number of processors in the system.

Share:
79,860
blank
Author by

blank

...

Updated on July 08, 2022

Comments

  • blank
    blank almost 2 years

    Correct me if I'm wrong, but I'm surprised this hasn't been asked before on here ...