Lably
Skip to content

Message passing

Technique for running a program on a computer without directly calling it

  • 7 min read
  • 5 chapters

Learn it on Lably

Message passing is ubiquitous in modern computer software. It is used as a way for the objects that make up a program to work with each other and as a means for objects and systems running on different computers (e.g., the Internet) to interact. Message passing may be implemented by various mechanisms, including channels.

Overview

Message passing is a technique for invoking behavior (i.e., running a program) on a computer. In contrast to the traditional technique of calling a program by name, message passing uses an object model to distinguish the general function from the specific implementations. The invoking program sends a message and relies on the object to select and execute the appropriate code. The justifications for using an intermediate layer essentially falls into two categories: encapsulation and distribution.

Message passing is a core technique used for communication between processes, threads, objects, or nodes in both concurrent and distributed systems. It enables software components to exchange information without sharing memory, often using communication channels, buffers, or middleware to transport messages between senders and receivers. In some models, message passing can be implemented synchronously, where the sender waits for a reply, or asynchronously, where messages are queued for later processing.

One application of message passing can be found in the domain of computer graphics. There are various complexities involved in manipulating graphic objects. For example, simply using the right formula to compute the area of an enclosed shape will vary depending on if the shape is a triangle, rectangle, ellipse, or circle. In traditional computer programming, this would result in long IF-THEN statements testing what sort of object the shape was and calling the appropriate code. The object-oriented way to handle this is to define a class called Shape with subclasses such as Rectangle and Ellipse (which, in turn, have subclasses Square and Circle) and then to simply send a message to any Shape asking it to compute its area. Each Shape object will then invoke the subclass's method with the formula appropriate for that kind of object.

Distributed message passing provides developers with a layer of the architecture that provides common services to build systems made up of sub-systems that run on disparate computers in different locations and at different times. When a distributed object is sending a message, the messaging layer can take care of issues such as:

  • Finding the process using different operating systems and programming languages, at different locations from where the message originated.
  • Saving the message on a queue if the appropriate object to handle the message is not currently running and then invoking the message when the object is available. Also, storing the result if needed until the sending object is ready to receive it.
  • Controlling various transactional requirements for distributed transactions, e.g. atomicity, consistency, isolation, durability (ACID) testing the data.

Sign in to keep reading

4 more chapters are free with a Lably account.

More in Computing and communication