[erlang-questions] Blocking NIFs
Fri Nov 19 19:05:49 CET 2010
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 <jeff.zellner@REDACTED>wrote:
> While I have read the erl_nif documentation (that says "Avoid doing lengthy
> 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 on
> 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 than
> '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