[erlang-questions] Blocking NIFs

Jeff Zellner jeff.zellner@REDACTED
Fri Nov 19 19:10:04 CET 2010


enif_thread_create sounds like what I'm looking for. I will give it a shot,
Thanks!

-Jeff

On Fri, Nov 19, 2010 at 1:05 PM, Rapsey <rapsey@REDACTED> 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.
>
>
> Sergej
>
>
> 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
>> are
>> called directly by the same scheduler thread that executed the calling
>> Erlang code. The calling scheduler will thus be blocked from doing any
>> other
>> 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
>> found
>> 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! :-)
>>
>> Cheers,
>> Jeff
>>
>
>


More information about the erlang-questions mailing list