The Erlang User's Guide describes the send operator as
8.9 Send
Expr1 ! Expr2
Sends the value of
Expr2
as a message to the process specified byExpr1
. The value ofExpr2
is also the return value of the expression.
Expr1
must evaluate to a pid, a registered name (atom), or a tuple{Name,Node}
.Name
is an atom andNode
is a node name, also an atom.
- If
Expr1
evaluates to a name, but this name is not registered, abadarg
run-time error occurs.- Sending a message to a pid never fails, even if the pid identifies a non-existing process.
- Distributed message sending, that is, if
Expr1
evaluates to a tuple{Name,Node}
(or a pid located at another node), also never fails.
In the case of distributed message sending, it is not clear to me what the first atom represents in {Name,Node}
from the code of the remote node or process.
Your help is appreciated.
In Erlang, each thread of execution is called a process. (Aside: the term "process" is usually used when the threads of execution share no data with each other and the term "thread" when they share data in some way. Threads of execution in Erlang share no data, that is why they are called processes).
A node is an executing Erlang runtime system that has been given a name, using the command-line flag -name (long names) or -sname (short names).
The grammar is a bit ambiguous in the sentence you're citing. The three options are:
The first is by far the most common. Registered names are intended to be used judiciously.
I'd recommend starting with the concurrency chapter from Learn You Some Erlang, and backtracking as necessary to earlier chapters: http://learnyousomeerlang.com/the-hitchhikers-guide-to-concurrency#dont-panic
let's say you have two nodes: node1@localhost and node2@localhost and you register an erlang process in node1 as process1.
You can send messages from node2 to process1 in node1 as:
{process1, node1@localhost} ! yourmessage.
Hope this will help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With