[erlang-questions] Is the monitor/2 function is much efficient in erlang 21?

18年梦醒 getonga2018@REDACTED
Tue Dec 11 10:25:12 CET 2018


I recently test the sbroker in erlang 21, but the skip_down_match test is
always failed, I check out the code and make a prototype of the code:
```
-module(a).

-export([start/0]).

start() ->
    Pid = spawn(fun() -> t() end),
    register(t_name, Pid),
    spawn(fun() -> t1() end),
    timer:sleep(1000).

t1() ->
    {_, _MRef} = spawn_monitor(fun() ->
                                       Pid = whereis(t_name),
                                       Pid ! {pid, self()},
                                       exit(normal)
                               end).
t() ->
    receive
        {pid, Pid} ->
            Ref = monitor(process, Pid),
            case demonitor(Ref, [flush, info]) of
                true ->
                    io:format("result is true");
                false ->
                    io:format("result is false")
            end
    end.

```
I run it like this:
```
$ /usr/local/otp_src_21.1.4/bin/erlc a.erl
$ /usr/local/otp_src_21.1.4/bin/erl -s a start -s init stop -noinput
result is true
$ rm a.beam
$ /usr/local/otp_src_20.3.8.15/bin/erlc a.erl
$ /usr/local/otp_src_20.3.8.15/bin/erl -s a start -s init stop -noinput
result is false
```
The same code, in erlang 21, the output is `result is true`, but in erlang
20, the output is `result is false`, that is why the test fail.

I just wonder why the same code but different version, why the result is
different?
Is the behaviour changed with the monitor/2 function?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181211/f21a4bca/attachment.htm>


More information about the erlang-questions mailing list