• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do Scala Actors have "spawn"

 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An Erlang book I'm reading says Erlang has 3 main parts with concurrency: receiving a message, sending a message (!), and spawning a process.

So Erlang has this thing called spawn. Does something like this exist in Scala?
 
Gabriel Claramunt
Ranch Hand
Posts: 375
Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure of what "spawn" does, but I guess it will be equivalent to:
Although Scala implements the concept of actors, I think Erlang provides better support for low-cost concurrency and recovery.
On the other hand, running in the JVM is a big plus and with Terracota you can get almost free clustering.
[ August 07, 2008: Message edited by: Gabriel Claramunt ]
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're right, Gabriel.

Doesn't Scala still use Java-style threads? Aren't they kind of expensive to create?

The Erlang book encourages creating lots and lots of processes - to the point that I think having them in the thousands is good.

Has anyone seen any process-creation benchmarks of Erlang vs Scala? I have a funny feeling the JVM can't keep up on process creation... or at least not yet.
 
Gabriel Claramunt
Ranch Hand
Posts: 375
Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually,I just found that Scala's event-based actors are threadless. Scala uses a pool of threads to serve all actor requests. If I recall correctly, Erlang does something similar.
In event based actors, messages are processed with the "react" keyword instead of "receive", the Actors tutorial explains how to use it
Also I found a detailed explanation of what happens behind the curtains in Event-Based Programming without Inversion of Control
Seems Scala's actors are almost like Erlang ones
[ August 11, 2008: Message edited by: Gabriel Claramunt ]
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marc Peabody:
Doesn't Scala still use Java-style threads? Aren't they kind of expensive to create?


Not if you use a thread pool. That's why they were put in Java long ago.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic