Skip to content

Instantly share code, notes, and snippets.

@niku
Created September 7, 2016 14:09
Show Gist options
  • Save niku/4f82069153e10dac231a99564e6564dd to your computer and use it in GitHub Desktop.
Save niku/4f82069153e10dac231a99564e6564dd to your computer and use it in GitHub Desktop.
「すごいErlangゆかいに学ぼう」の 「12.3 プロセスに名前を付ける」にある表についての疑問
judge2(Band, Album) ->
critic ! {self(), {Band, Album}},
Pid = whereis(critic),
receive
{Pid, Criticism} -> Criticism
after 2000 ->
timeout end.

すごいErlangゆかいに学ぼう の 12.3 プロセスに名前を付けるにある表についての疑問

judge2 を実行すると,

メインプロセス criticプロセス
1. critic ! Message
2. criticがreceive
3. criticが応答
4. criticが死亡
5. whereisが失敗
6. criticが再開される
7. コードがクラッシュ

のようになることがあると記述されています.

しかしwhereis/1 によると名前が登録されていないときは単に undefined を返すだけなので,whereisが失敗することはなく

メインプロセス criticプロセス
1. critic ! Message
2. criticがreceive
3. criticが応答
4. criticが死亡
5. whereisがundefinedを返す
6. criticが再開される
7. pidとundefinedを比較して決してマッチしない

になるのではないかという疑問です.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment