1%% This tests that the race condition detection between whereis/register
2%% is robust w.r.t. having the calls in separate functions.
3
4-module(whereis_diff_functions1_nested).
5-export([test/2]).
6
7test(AnAtom, Fun) ->
8  start(AnAtom, Fun).
9
10start(AnAtom, Fun) ->
11  case whereis(AnAtom) of
12    undefined ->
13      Pid = spawn(Fun),
14      race1(AnAtom, Pid);
15    P when is_pid(P) ->
16      true
17  end.
18
19race1(Atom, Pid) ->
20  race2(Atom, Pid).
21
22race2(Atom, Pid) ->
23  register(Atom, Pid).
24