Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actors (scala/akka): is it implied that the receive method will be accessed in a threadsafe manner?

I assume that the messages will be received and processed in a threadsafe manner. However, I have been reading (some) akka/scala docs but I didn't encounter the keyword 'threadsafe' yet.

like image 384
Asad Iqbal Avatar asked Oct 14 '11 19:10

Asad Iqbal


2 Answers

It is probably because the actor model assumes that each actor instance processes its own mailbox sequentially. That means it should never happen, that two or more concurrent threads execute single actor instance's code. Technically you could create a method in an actor's class (because it is still an object) and call it from multiple threads concurrently, but this would be a major departure from the actor's usage rules and you would do it "at your own risk", because then you would lose all thread-safety guarantees of that model.

This is also one of the reasons, why Akka introduced a concept of ActorRef - a handle, that lets you communicate with the actor through message passing, but not by calling its methods directly.

like image 177
Przemek Pokrywka Avatar answered Oct 07 '22 12:10

Przemek Pokrywka


I think we have it pretty well documented: http://doc.akka.io/docs/akka/2.3.9/general/jmm.html

like image 30
Viktor Klang Avatar answered Oct 07 '22 13:10

Viktor Klang