Blocking NIFs

Jeff Zellner <>
Fri Nov 19 19:05:45 CET 2010


To clarify a bit:

I'm writing an ncurses interface in NIFs, and using it running with
-noinput/-noshell. I'm looking to capture actual key presses, not prompted
input.

I'd like to avoid dealing with a port program or a driver just for the
single blocking operation I want to do.

On Fri, Nov 19, 2010 at 12:30 PM, Jeff Zellner <>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