[erlang-questions] New NIF behavior in R15???

Matthew Evans <>
Sat Oct 15 15:45:04 CEST 2011


>From what I understand the new NIF features are intended to supercede the use of linked in drivers.

NIFS are fast to call C code, much faster than linked in drivers, but as you know they can block the scheduler if your C code does something nasty like read from a driver or sit in a loop.

I can, of course, use a NIF as an accessor to a C API that can dispatch a message to a thread in a thread pool (as you would using a linked in driver, in fact I believe the NIF threading functions are wrappers around the exisiting linked in driver functions).

What the new NIFS provide is the ability to "convert" an Erlang process into native code. Effectively you will invoke native code that will enter into its own event loop on one of the threads in the thread pool and other Erlang processes can send/receive messages to it. Basically providing an "OTP" like interface to your C code.  

Please see:
http://www.erlang-factory.com/upload/presentations/377/RickardGreen-NativeInterface.pdf

Matt

Date: Sat, 15 Oct 2011 13:10:26 +0100
From: 
To: 
CC: 
Subject: Re: [erlang-questions] New NIF behavior in R15???

Sure I get that it's possible but as I said, I've not used NIFs yet and from reading the documentation you'd expect that the *expected* thing to do with a NIFs is keep it bound to the calling process and use it for fast synchronous calls, whereas linked-in drivers provide an explicit API for executing tasks asynchronously. 


On 15 October 2011 12:59, Joel Reymont <> wrote:



On Oct 15, 2011, at 12:27 PM, Tim Watson wrote:



> I was under the impression that linked-in drivers are the way to go if you want to avoid blocking the emulator whilst potentially long running tasks execute.



What is preventing you from using a queue to talk to your NIF?



You can then spawn as many threads as you like in your C code to avoid blocking the emulator.



--------------------------------------------------------------------------

- for hire: mac osx device driver ninja, kernel extensions and usb drivers

---------------------+------------+---------------------------------------

http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont

---------------------+------------+---------------------------------------






_______________________________________________
erlang-questions mailing list

http://erlang.org/mailman/listinfo/erlang-questions 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111015/23a4b220/attachment.html>


More information about the erlang-questions mailing list