[erlang-questions] NIF vs. Linked-in Drivers

Sverker Eriksson <>
Tue Dec 8 19:49:18 CET 2009

Evans, Matthew wrote:
> Hi,
> Are there any guidelines as to the use of the new Erlang NIF vs. a linked-in port driver?
> We have an application that needs to access C code, and are currently thinking (and have used in the past) a linked-in port driver. Under what situations would that approach be better than a NIF, and visa versa?
A driver is definitely better if you want to be asynchronous and react 
on events from some "device".

NIFs are by nature synchronous. You call them as any Erlang function and 
get a return value back. You will block the calling scheduler thread 
until the NIF returns, so you don't want to do too heavy computations in 
one call. Drivers currently have more support like threading and message 
sending to work around that, but the NIFs will most probably get at 
least some sort of support to be more "interruptable".

/Sverker, Erlang/OTP Ericsson

More information about the erlang-questions mailing list