[erlang-questions] dirty scheduler segfault

Daniel Goertzen daniel.goertzen@REDACTED
Fri Oct 31 21:33:33 CET 2014


I am seeing a segfault that seems to be related to dirty schedulers.  I've
reduced the fault to the erlang and C nif module below which executes the
same nif with either the io dirty scheduler, the cpu dirty scheduler, or
the normal erlang scheduler.


When I start the emulator and run either dirty nif, I get a segfault. ( see
https://gist.github.com/goertzenator/6237e0200a5f7bf22976)

The non-dirty nif works properly, and If I run the non-dirty nif first then
subsequent calls to the dirty nifs work fine.

Also, if I reduce the nif list length from 11 to 10, the dirty nifs work on
the first go.

Is there a bug here or am I doing something dumb?

Thanks,
Dan.



-module(dlibusb).
-author("goertzen").

-on_load(init/0).
-include_lib("eunit/include/eunit.hrl").

-export([mytest_io/0, mytest_cpu/0, mytest_none/0]).

mytest_io() ->
    erlang:nif_error(nif_library_not_loaded).
mytest_cpu() ->
    erlang:nif_error(nif_library_not_loaded).
mytest_none() ->
    erlang:nif_error(nif_library_not_loaded).

init() ->
    PrivDir = code:priv_dir(dlibusb),
    Lib = filename:join([PrivDir, "dlibusb"]),
    ok = erlang:load_nif(Lib, 0).




#include <erl_nif.h>

int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
{
   return 0;
}

void unload(ErlNifEnv* env, void* priv_data)
{

}

ERL_NIF_TERM mytest(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    const int cnt=11;  // doesn't segfault if cnt=10
    ERL_NIF_TERM arr[cnt];
    ERL_NIF_TERM atom_ok;
    atom_ok = enif_make_atom(env, "ok");
    for(int i=0; i<cnt; i++)
    {
        arr[i] = atom_ok;
    }

    return enif_make_list_from_array(env, arr, cnt);
}

static ErlNifFunc nif_funcs[] = {
    {"mytest_io",      0, mytest, ERL_NIF_DIRTY_JOB_IO_BOUND},
    {"mytest_cpu",     0, mytest, ERL_NIF_DIRTY_JOB_CPU_BOUND},
    {"mytest_none",    0, mytest}
};

ERL_NIF_INIT(dlibusb, nif_funcs, load, 0, 0, unload)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141031/9b79b081/attachment.htm>


More information about the erlang-questions mailing list