1.4 A high-level perspective on concurrency

Let's take a step back and look at actor-based programming from a higher-level perspective. To appreciate the difference, and the relationship, between more traditional concurrency constructs and actors, it helps to pay a brief visit to the local railroad yard.

Imagine yourself standing on a bridge overlooking the multitude of individual tracks entering the rail yard. You can observe many seemingly independent activities taking place, such as trains arriving and leaving, cars being loaded and unloaded, and so on.

Suppose, then, that your job was to design such a railroad yard. Thinking in terms of threads, locks, monitors, and so on is similar to the problem of figuring out how to make sure that trains running on parallel tracks don't collide. It is an important requirement; without that, the rail yard would be a dangerous place. To accomplish that task, you would employ specialized artifacts, such as semaphores, monitors, and switches.

Actors illuminate the same rail yard from the higher perspective of ensuring that all the concurrent activities taking place at the rail yard progress smoothly: All the delivery vehicles find ways to train cars; all the trains can make their progress through the tracks; and all the activities are properly coordinated.

You will need both perspectives when designing a rail yard: Thinking from the relatively low-level perspective of individual tracks ensures that trains don't inadvertently cross paths; thinking from the perspective of the entire facility helps ensure that your design facilitates smooth overall operation, and that your rail yard can scale, if needed, to accommodate increased traffic. Simply adding new rail tracks only goes so far: you need some overall design principles to ensure that the whole rail yard can grow to handle increased traffic, and that greater traffic can scale up to the full capacity of the tracks.

Working on the relatively low-level details of individual tracks (or problems associated with interleaving threads), on the one hand, and the higher-level perspective of the entire facility (actors) on the other, require somewhat different skills and experience. An actor-based system is often implemented in terms of threads, locks, monitors, and the like, but actors hide those low-level details and allow you to think of concurrent programs from a higher vantage point.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset