DOC PREVIEW
TRINITY CSCI 1321 - Actors

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Actors11-28-2011Opening DiscussionShould you use XML or direct access for your project?Finishing the file example.Challenges in ParallelismWe have already seen that you need to have your programs multithreaded to take full advantage of modern processors.Unfortunately, the standard threading model can be very difficult to use. Race-conditions and deadlock can be difficult to avoid and are extremely challenging to debug.ActorsAnother approach to parallelism is the actor model. This is the main approach to programming Erlang which is used a lot in telecom.Scala includes an actor package that supports this model.With actors, data isn't shared. You send messages instead of calling methods.Let's take a minute to look in the API.MessagesActors respond to messages that are sent to them. The actions of actors are done in parallel.Use ! to send a message.It is ideal to use case classes for messages. That way you get pattern matching and immutable data.Messages go to an actors inbox. Sending messages does not block.The act MethodThe main logic for an actor goes in the act method.Call receive to process a message.Put the receive inside a loop to do so repeatedly.Receive takes a partial function that handles the appropriate messages.Don't block.Short VersionThere is a helper method in the Actor object that takes a function for the body of the act method.You should import scala.actors.Actor, then you can call actor { body }.Playing with ActorsLet's play a little with Actors given what we know so far.Minute


View Full Document

TRINITY CSCI 1321 - Actors

Documents in this Course
Recursion

Recursion

11 pages

Iterators

Iterators

10 pages

Recursion

Recursion

15 pages

Recursion

Recursion

10 pages

Threads

Threads

7 pages

Trees

Trees

11 pages

Load more
Download Actors
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Actors and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Actors 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?