If I understood, the actor model is just like the object model, but with a few differences:
- EVERY object spawns it's own separate thread and its not a problem even when you have thousands of objects.
- Actors don't interact by calling functions and getting return values but instead by sending and receiving messages.
- If you don't violate that model your app will be using concurrency to its full power without any risks of race conditions.
- Everything you can do in OO you can do using actors but better, the problem being that everything we coded in the last years was OO based - but a transition is imminent.
So for instance, suppose I have to define 3d vector class/actor, create two instance and call a sum operation on them.
OBJECT ORIENTED:
class V3d {
constructor V3d(x,y,z) //bla
float x,y,z;
function sum(V3d b)
{
return V3d(x+b.x,y+b.y,z+b.z);
}
}
//using:
mySum = V3d(1,2,3).sum(V3d(3,2,1)) //creates 2 instances, sum, returns instantly
drawPoint(mySum) //uses the result
ACTOR MODEL:
actor V3d
{
constructor V3d(x,y,z) //bla
float x,y,z;
loop
{
receive 'sum',b:V3d :
send(caller,'sumResult',V3d(x+b.x,y+b.y,z+b.z))
}
}
//using:
send(V3d(1,2,3),'sum',V3d(3,2,1)) //creates 2 instances, send to the first one a request to sum with the second one
loop
{
receive 'sumResult',result:
drawPoint(result) //receives result and draws it
}
Is that it? Or am I completely wrong?