1
%% This tests the presence of possible races due to an ets:lookup/ets:insert
2
%% combination. It takes into account control flow that might exist.
4
-module(ets_insert_control_flow5).
8
Table = ets:new(table, [public]),
12
root -> ets:lookup(Table, pass);
13
user -> ets:lookup(Table, pass);
14
Other -> [{undefined, -1}]
16
[{_, Msg}] = ets:lookup(Table, welcome_msg),
18
-1 -> io:format("\nUnknown User\n", []);
22
ets:insert(Table, {welcome_msg, Msg ++ "root"}),
23
ets:insert(Table, {pass, Pass = generate_password(N) ++ generate_password(N+1)});
25
ets:insert(Table, {welcome_msg, Msg ++ "user"}),
26
ets:insert(Table, {pass, Pass = generate_password(N)})
28
io:format("\nYour new pass is ~w\n", [Pass]);
30
io:format("\nYour pass is ~w\n", [P])
33
generate_password(N) ->
34
lists:map(fun (_) -> random:uniform(90)+$\s+1 end, lists:seq(1,N)).