Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 223
blank Avatar asked Dec 05 '09 20:12

blank


People also ask

What is the difference between message passing and shared memory model?

Message passing is a time consuming process because it is implemented through kernel (system calls). In shared memory make sure that the processes are not writing to the same location simultaneously. Message passing is useful for sharing small amounts of data so that conflicts need not occur.

What is the difference between shared memory and message queue?

Message queue has inherent synchronization overhead, guarantee of safety at cost of performance. Shared memory has no safeguards - if two threads access it simultaneously, they will possibly conflict (write inconsistent data) unless you assure thread safety yourself.

What is the purpose of message passing and shared memory?

An advantage of shared memory model is that memory communication is faster as compared to the message passing model on the same machine. However, shared memory model may create problems such as synchronization and memory protection that need to be addressed.

What is difference between shared memory and distributed memory?

Shared memory allows multiple processing elements to share the same location in memory (that is to see each others reads and writes) without any other special directives, while distributed memory requires explicit commands to transfer data from one processing element to another.


2 Answers

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!

like image 57
Chris Pitman Avatar answered Sep 23 '22 08:09

Chris Pitman


  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.

like image 25
Farah Nazifa Avatar answered Sep 24 '22 08:09

Farah Nazifa