1
%% This tests the presence of possible races due to an ets:lookup/ets:insert
2
%% combination. It takes into account multiple ets:inserts that might exist.
4
-module(ets_insert_double2).
8
io:format("Created ~w\n", [ets:new(foo, [named_table, public])]),
9
ets:insert(foo, {Random, random:uniform(150)}),
10
io:format("Inserted ~w\n", [{_, N}] = ets:lookup(foo, Random)),
11
case (N rem 2 == 0) of
13
io:format("\nInserted an even integer\n", []),
14
io:format("\nWill make it odd and generate new password\n", []),
15
ets:insert(foo, [{Random, N+1}, {Pass, generate_password(Pass, N)}]);
17
io:format("\nInserted an odd integer\n", []),
18
io:format("\nWill make it even and generate new password\n", []),
19
ets:insert(foo, [{Random, N+1}, {Pass, generate_password(Pass, N)}])
21
io:format("Update complete\n", []),
22
ObjectList = ets:lookup(foo, Pass),
23
io:format("New password: ~w\n", [ObjectList]),
24
ets:insert(foo, {Pass, 'empty'}).
26
generate_password(Pass, N) ->
27
[{_, P}] = ets:lookup(foo, Pass),
28
lists:map(fun (_) -> random:uniform(90)+P+$\s+1 end, lists:seq(1,N)).