[erlang-bugs] ets:new/2 and ets:all/0 concurrency issue

Florian Schintke schintke@REDACTED
Wed Feb 5 17:39:32 CET 2014


Hi,

suppose we call ets:new() and ets:all() in sequence. We expect to see
the newly created table in the output of ets:all().

If a single process calls ets:new() and ets:all() in sequence
everything works as expected.

If two concurrent processes A and B call ets:new() and ets:all(), it
can happen that the table created by process A is not listed in
ets:all() output of process A, or the table created by process B is
not listed in ets:all() of process B. This violates the sequential
semantics one would expect from sequential code.

Below is a minimal example to reproduce the issue.

Tested with

Erlang R16B02 (erts-5.10.3) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Typical output of the example:
---
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table not listed in ets:all() a bit later!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table not listed in ets:all() a bit later!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
Table not listed in ets:all()!!!
Table listed shortly after!!!
...
---

Kind regards,
Florian




-module(etstest).

-export([test/0]).

test() ->
    spawn(fun() -> test1() end),
    test1(),
    ok.

test1() ->
    Table = ets:new(any_table_name, []),
    case lists:member(Table, ets:all()) of
        false ->
            io:format("Table not listed in ets:all()!!!~n"),
            timer:sleep(15),
            case lists:member(Table, ets:all()) of
                false ->
                    io:format("Table not listed in ets:all() a bit later!!!~n"),
                    false;
                true ->
                    io:format("Table listed shortly after!!!~n"),
                    true
            end;
        true ->
            ets:delete(Table)
    end,
    test1().



More information about the erlang-bugs mailing list