Search⌘ K

Message Passing: Example

Explore how message passing concurrency works in D through a simulation of robots moving independently. Understand how threads communicate robot movements to an owner thread, which serializes output by receiving messages. This lesson helps you apply concurrency concepts for managing independent tasks and communication in your D programs.

We'll cover the following...

Example

Let’s use what we have discussed so far in a simulation program.

The following program simulates independent robots moving around randomly in a two-dimensional space. The movement of each robot is handled by a separate thread that takes three pieces of information when started:

  • The ...