If we think that the actors are people, then the messages are like ... messages.
Say that the boss wants the square root of the list of numbers a, and does not want to do all the calculations on his own. He can hire some Workers, and the Boss will find out their Phone Numbers.
, SMS : " a_i, 555-1234 , ". . .
+
| Boss |
+
| sqrt(i=1, a_i=16) +
β
+
....
, , SMS . .
+------+ set_result(i=0, val=3) +------------+
| Boss | <------------------------ | Worker 0 |
+------+ +------------+
^ set_result(i=1, val=4) +------------+
β--------------------------- | Worker 1 |
+------------+
....
- , , . ( , .)
actor Boss:
receive('run'):
worker_addrs = spawn_many(SqrtWorker, len(a))
for i, addr in enumerate(worker_addrs):
send(addr, 'sqrt', reply_addr=self, i=i, a_i=a[i])
receive('set_value', i, val):
a[i] = val
actor SqrtWorker:
receive('sqrt', reply_addr, i, a_i):
send(reply_addr, 'set_value', i, sqrt(a_i))
quit()
" ", . a . , a - .
, a shared? , .
+
| Boss |
+
+
| a |
+
( , a.)
+------+ +----------+
| Boss | | Worker 0 |
+------+ +----------+
|
+---+ |
| a | <---------------------------β
+---+ get(i=0)
...
+
| Boss | | Worker 0 |
+
^
+
| a |
+
list_val.
+------+ set_result(i=0, val=3) +----------+
| Boss | <------------------------------ | Worker 0 |
+------+ +----------+
+---+
| a |
+---+
, ,
+
| Boss | | Worker 0 |
+
| set(i=0, val=3)
| +
β
+
? - , a, , / . , .