<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>On tis, 2018-12-11 at 17:25 +0800, 18年梦醒 wrote:</div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">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:</div><div dir="ltr">```</div><div dir="ltr"><div dir="ltr">-module(a).</div><div dir="ltr"><br></div><div dir="ltr">-export([start/0]).</div><div dir="ltr"><br></div><div dir="ltr">start() -></div><div dir="ltr">    Pid = spawn(fun() -> t() end),</div><div dir="ltr">    register(t_name, Pid),</div><div dir="ltr">    spawn(fun() -> t1() end),</div><div dir="ltr">    timer:sleep(1000).</div><div dir="ltr"><br></div><div dir="ltr">t1() -></div><div dir="ltr">    {_, _MRef} = spawn_monitor(fun() -></div><div dir="ltr">                                       Pid = whereis(t_name),</div><div dir="ltr">                                       Pid ! {pid, self()},</div><div dir="ltr">                                       exit(normal)</div><div dir="ltr">                               end).</div><div dir="ltr">t() -></div><div dir="ltr">    receive</div><div dir="ltr">        {pid, Pid} -></div><div dir="ltr">            Ref = monitor(process, Pid),</div><div dir="ltr">            case demonitor(Ref, [flush, info]) of</div><div dir="ltr">                true -></div><div dir="ltr">                    io:format("result is true");</div><div dir="ltr">                false -></div><div dir="ltr">                    io:format("result is false")</div><div dir="ltr">            end</div><div dir="ltr">    end.</div><div><br></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><br></div><div>Yes the behavior has changed in 21, but both behaviors are correct and you are not guaranteed to always get the same behavior in any OTP version.</div><div><br></div><div>The program contains a race condition.</div><div>At the time demonitor(Ref, [flush,info]) is called you don't know if the monitored process is still alive or not.</div><div><br></div><div>If it's still alive, the monitor will be remove and demonitor returns true.</div><div>If it's not alive, no monitor exists (a 'DOWN' message/signal has instead been sent which will be removed by the 'flush' option) and demonitor will return false.</div><div><br></div><div><br></div><div>/Sverker</div><div><br></div><div><br></div><div><br></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"></div></div></div></div></div></div></div></div></div></div></blockquote><div>
</div></body></html>