aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/race_tests_SUITE_data/src/whereis_diff_functions1_nested.erl
blob: 0a77c78ba3fc387fd3c86788a6a905295a2840f4 (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
%% This tests that the race condition detection between whereis/register
%% is robust w.r.t. having the calls in separate functions.

-module(whereis_diff_functions1_nested).
-export([test/2]).

test(AnAtom, Fun) ->
  start(AnAtom, Fun).

start(AnAtom, Fun) ->
  case whereis(AnAtom) of
    undefined ->
      Pid = spawn(Fun),
      race1(AnAtom, Pid);
    P when is_pid(P) ->
      true
  end.

race1(Atom, Pid) ->
  race2(Atom, Pid).

race2(Atom, Pid) -> 
  register(Atom, Pid).