Erlang, register/2: exception error bad argument -
i want write program creates 2 processes. first print number , send second process , on. have problem in start function.
-module(zad). -export([start/0, one/0, two/0]). one() -> receive {go1, n} -> io:format("1 ~w~n", [n]), 2 ! {go2, n+1}, one(); {go2, 50} -> io:format("end ~w~n", [n+1]), 2 ! finished end. two() -> receive finished -> io:format("two finished~n", []); {go2, n} -> io:format("2 ~w~n", [n]), 1 ! {go1, n+1 }, two() end. start() -> register(two, spawn(zad, two, [])), register(one, spawn(zad, one, [])), 1 ! {go1, 0}.
here's error
** exception error: bad argument in function register/2 called register(two,<0.146.0>) in call zad:start/0 (zad.erl, line 29)
does mean cant register 2 processes in start? wrong code?
update weird. after changed
{go2, 50} -> io:format("end ~w~n", [n+1]),
to
{go2, 50} -> io:format("end ~w~n", [50]),
error disappeared. it's strange because problem in one()
, error in register(two)
you can register 2 processes in start/0
. means values passing register/2
wrong. documentation(http://erlang.org/doc/man/erlang.html#register-2):
failures:
badarg
if pidorport not existing local process or port.badarg
if regname in use.badarg
if process or port registered (already has name).badarg
if regname atomundefined
.
likely has happened process died before register/2
called (see first failure in list above).
Comments
Post a Comment