Previous | Next --- Slide 38 of 57
Back to Lecture Thumbnails

To compare the message passing model with shared memory model, two advantages of message passing I can think of:

  1. With shared memory, synchronization primitives have to be dealt by the programme carefully. It's error prone and hard to reason about the programme state. Message passing model doesn't have to deal with that.

  2. Message passing model scales up more easily than shared memory model, where a group of commodity hardwares can be organized and provide lots of computation power as a cluster. Getting a cluster of hardwares sharing the same memory space is harder to achieve.


I will follow-up with two disadvantages of message passing?

  • Higher latency: Message passing is usually built on top of lower-level primitives, and thus can be less efficient;
  • Limited usage: For example, message passing cannot be used for a synchronized lock / semaphore, unlike the shared memory model where a lock is simply "Lock *".

I think there should be alternative ways to implement synchronization in message passing model by message sending and receiving.

The greatest part of shared memory model is that it is an extension of uniprocessor programming. So the program would not change when it scales to multiple machines. Because the underlying hardware will take care of it.

However, when the application scales into clusters with thousands of nodes, it is hard to get them share the same memory address space. This is why message passing is introduced. It requires the programmer to take care of the cross-nodes communication.

In a nutshell, I think shared memory model is better suited for modules that run on a single machine. Message passing model is designed for modules that scales on clusters.


In message passing, are the message IDs hard-coded and chosen by the programmer or are they chosen dynamically in some sense, where the sender knows who to send it to and the receiver knows who to expect a message from?


@aeu In the scheme here it looks like the ids have to be specified. Otherwise if thread 2 was waiting on two different values from thread 1, it wouldn't know which one it was getting when it received a message.

These message passing semantics look very similar to the process calculus covered in 15-312 (, which gives a more rigorous abstraction for a concurrent communication model.


According to one of the project I did in another class, a thread can first send signal and then send the object. Because a signal is much smaller than real object, it will have lower delay. So I think they can use signal to implement synchronization in message passing model? Beside, I have another question: is there any differences or connections between message passing model and remote procedure call?


There can be lots of tricks with message passing model. Like a project I did in Distributed system, we need to implement a RPC call, which is basically same thing with message passing between threads. Depending on the protocols you are used, you need to make sure receiver to get exact number of bytes it needed. Besides, marshaling some complex data structures containing pointers is also tricky.