Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 20. Actors > Thread Sharing

20.7. Thread Sharing

Consider an actor that sends a message to another actor. It is easy to implement the control flow if each actor runs in a separate thread. The sending actor places a message in the mailbox, and its thread keeps on going. The receiving actor’s thread is awakened whenever an item is placed in the mailbox.

Some programs contain so many actors that it would be expensive to create a separate thread for each of them. Could we run multiple actors in the same thread? Let’s assume that actors spend most of their time waiting for messages. Instead of having each of them block on a separate thread, we can have a single thread executing the message handling functions of multiple actors. This works, provided each message handling function only does a small amount of work before it waits for the next message.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial