[erlang-questions] Blocking NIFs
Fri Nov 19 19:10:04 CET 2010
enif_thread_create sounds like what I'm looking for. I will give it a shot,
On Fri, Nov 19, 2010 at 1:05 PM, Rapsey <> wrote:
> I don't understand exactly what you mean by "async threads". I presume you
> don't mean blocking within a NIF thread (created with enif_thread_create),
> because that would work and it is how you should be doing it.
> Create a NIF thread, block there. Once you get an event, send a message
> from that thread to an erlang process.
> On Fri, Nov 19, 2010 at 6:30 PM, Jeff Zellner <>wrote:
>> While I have read the erl_nif documentation (that says "Avoid doing
>> work in NIF calls as that may degrade the responsiveness of the VM. NIFs
>> called directly by the same scheduler thread that executed the calling
>> Erlang code. The calling scheduler will thus be blocked from doing any
>> work until the NIF returns.") -- I'm trying to do keyboard input in a NIF.
>> Is this absolutely a bad idea, or is there a way to make it work? I've
>> that simple example programs, running ~2 processes, one of them blocking
>> a getch() in a NIF works fine -- unfortunately trying to integrate that
>> blocking NIF call into a larger program with upwards of 10 processes seems
>> to not work at all, regardless of how many async threads I use.
>> Can anyone give me some insight into this? Preferably something other
>> 'don't use NIFs to do that' -- I will eventually give up if it's just not
>> workable, but I'm not ready to do that yet! :-)
More information about the erlang-questions