[erlang-questions] Concurrent compile

Dominic Williams xpdoka@REDACTED
Fri Apr 20 00:52:29 CEST 2007


Hello,

Running the following module on a directory that contains several 
correct .erl files seems to demonstrate that compile:file/2 cannot be 
called concurrently. Is that normal? I could not find any mention of it 
in the documentation.

-module (pcompile).
-export ([run/1]).

run(Dir) ->
    {{sync_errors, sync_errors(Dir)},
     {async_errors, async_errors(Dir)}}.

sync_errors(Dir) ->
    lists:filter(
      fun is_error/1,
      filelib:fold_files(Dir, "\\.erl$", false, fun sync/2, [])).

async_errors(Dir) ->
    Pids = filelib:fold_files(Dir, "\\.erl$", false, fun async/2, []),
    Results = [receive M -> M after 1000 -> timeout end || _ <- Pids],
    lists:filter(
      fun is_error/1,
      Results).

is_error({ok, _, _}) -> false;
is_error({error, _, _}) -> true.

sync(File, Acc) ->
    [compile(File) | Acc].

async(File, Acc) ->
    Self = self(),
    Compile = fun() -> R = compile(File), Self ! R end,
    [spawn (Compile) | Acc].

compile(File) ->
    compile:file(File, [return]).


Example output (Mac OS X):

Eshell V5.4.12  (abort with ^G)
1> pcompile:run("tmp").
pcompile:run("tmp").
{{sync_errors,[]},
 {async_errors,[{error,[{"tmp/nw.erl",
                         [{none,compile,
                                {crash,
                                    parse_module,
                                    {badarg,
                                        [{ets,
                                             new,
                                             [compiler__tab,[...]]},
                                         {compile,parse_module,1},
                                         {compile,
                                             
'-internal_comp/4-anonymous-1-',
                                             2},
                                         {compile,fold_comp,3},
                                         {compile,internal_comp|...},
                                         {compile|...}]}}}]}],
                       []},
                {error,[{"tmp/foo.erl",
                         [{none,compile,
                                {crash,
                                    parse_module,
                                    {badarg,
                                        [{ets,new,[compiler__tab,[...]]},
                                         {compile,parse_module,1},
                                         {compile,
                                             
'-internal_comp/4-anonymous-1-'|...},
                                         {compile,fold_comp|...},
                                         {compile|...},
                                         {...}]}}}]}],
                       []}]}}
2>

Regards,

Dominic Williams
http://www.dominicwilliams.net

----



More information about the erlang-questions mailing list