[erlang-questions] 2 (unrelated) questions.

Geoff Cant nem@REDACTED
Wed Oct 26 22:34:06 CEST 2011


On 2011-10-26, at 08:25 , Paul Barry wrote:
> Q2. Being able to register a spawned process is cool, but why can't I
> register a process that is spawned remotely?  That is, why does this
> line of code give me a "badarg"?
> 
>     register(the_board, spawn('server@REDACTED', displayboard,
> putmessage, [])).


You can only register local pids and ports. I'm not sure why this restriction is enforced - maybe the erts people have more information.

In practice it's easy to work around. Register the name on the remote node and then use the {the_board, 'server@REDACTED'} ({RegisteredName, Node}) form instead of using a bare registered name or pid. This form is a valid argument to the ! send function.

As others have mentioned there are other process registries you can use (gproc, ngproc, proc_reg, global) that allow the registration of remote pids (and usually allow names to be terms instead of just atoms).

Cheers,
--
Geoff Cant







More information about the erlang-questions mailing list