Previous | Next --- Slide 38 of 60
Back to Lecture Thumbnails
hzxa21

Locking is not needed because all the data in the message are private data. No other threads will come and mess the data.

apadwekar

Note (in contrast) for shared address spaces the threads can just agree on the location of a variable and both use it rather than sending messages.

maddy

There is no locking required in the message passing model as each thread has its own private variables and no trampling of data can happen from another thread.

jmc

As @apadwekar said, the message passing model can be thought of (albeit a more theoretical, and perhaps not useful, conceptualization) as a special case of the shared address space where each thread shares only a designated space with other threads, allowing them to write to it, and only reading from (not writing to) it. This eliminates the possibility of race conditions on the shared space.

axiao

One possible disadvantage of using a message passing model is that it seems to require more work to make sure that all threads are consistent. For example, suppose we have n threads that share some kind of configuration variable that should be consistent across all threads. Then updating this variable for all threads will take n - 1 messages, while the shared address model would only require a single update (although the update requires a write lock).

Abandon

This kind of communication model reminds me of an interesting programming language, Golang, which is very suitable for developing distributed programs. The variable type channel exactly supports the communication between different threads.

yeq

The throughput of message passing model is much lower than that of the shared address space model, but the implementation is easier because each thread only maintains its own private data. The operating system needs to provides every process its own virtual address space. As the machine goes bigger, it's very inefficient to make a single address space to span thousands of processors and manage the mapping between virtual address space and physical memory. That's why for parallel program running on a large bunch of processors, usually sending message is preferred.

o_o

If I'm understanding this correctly, does this mean that message passing is easier if we have many processors because it doesn't need to use locks; but it may take more work? And the shared address model is better if we have fewer processors so we don't have to deal with mapping address space for all of the processors.

metainf

@o_o I think that it's not the fact that locks have to be used, but instead it becomes difficult to physically connect all the processors together.

yes

@Abandon That's an interesting comparison. I wonder how goroutines are implemented on the backend and if these are more analogous they appear?

mario

Since the threads do not share an address space, they have different variables. Consequently, they communicate by writing to one area where they can send and receive messages.

connorwa

The Mach kernel, developed here at CMU, relies heavily on the message-passing concept.