aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/race_SUITE_data/src/ets_insert_public.erl
blob: 4caa9fe8a0d64c79054c4fc47ac4b18ada956f1b (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 the presence of possible races due to an ets:lookup/ets:insert
%% combination. It takes into account any public ETS tables that might exist.

-module(ets_insert_public).

-export([main/1]).

%% Main
main(Foo) ->
    make_table(Foo),
    ets:insert(Foo, {counter, 0}),
    [{_, N}] = ets:lookup(Foo, counter),
    NewN = N + 1,
    ets:insert(Foo, {counter, NewN}),
    NewN.

make_table(Foo) ->
    init(Foo).

init(Foo) ->
    ets:new(Foo, [named_table, public]),
    ets:insert(Foo, {counter, 0}),
    {ok, feeling_good}.