Chapter 13
Programming with Actors

We often use multithreading and concurrency when programming complex, time-consuming applications, to improve the response time or performance. Traditional concurrency solutions, sadly, lead to several issues, such as thread safety, race conditions, deadlocks, livelocks, and hard-to-read error prone code. Shared mutability is the number-one culprit.

Avoid shared mutability and you’ve removed so many issues. But how to avoid it? That’s where actors come in. Actors help to turn shared mutability into isolated mutability. Actors are active objects that guarantee mutual exclusion of access. No two threads will ever work on an actor at the same time. Due to this natural self-imposed mutual exclusion, any data stored within actors is automatically thread-safe—no explicit synchronization is needed.

If you can meaningfully split a problem into subtasks—divide-and-conquer—then you can use actors to solve the problem with good design clarity and avoid the general concurrency issues.

In this chapter we’ll take a problem that can benefit from concurrency, examine the issues, and then explore actors and use them to solve the problem.

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

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