aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test/receive_SUITE_data/ref_opt/no_5.erl
blob: 4fbde3a83da24a314dab4d3d3a9ebaf630c76f2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-module(no_5).
-compile([export_all,nowarn_export_all]).

?MODULE() ->
    ok.

%% Nested receives were not handled properly.

confusing_recv_mark(Pid) ->
    Ref = make_ref(),
    %% There would be a recv_mark here.
    MRef = erlang:monitor(process, Pid),
    receive
        Ref ->
            %% And a recv_set here.
            receive
                MRef -> gurka
            end;
        MRef ->
            gaffel
    end.

%% The optimization could potentially be improved to
%% handle matching of multiple refs, like this:

proper_recv_mark(Pid) ->
    %% Place the recv_mark before the creation of both refs.
    Ref = make_ref(),
    MRef = erlang:monitor(process, Pid),
    %% Place the recv_set here.
    receive
        Ref ->
            receive
                MRef -> gurka
            end;
        MRef ->
            gaffel
    end.