[erlang-questions] NIF Callback Pids

Theepan <>
Tue Sep 29 19:36:47 CEST 2015


NIF provides for implementing 'functions with header in Erlang, and body in
C'. This improves performance significantly against Port Drivers.

I am not sure why you wanted to send messages to a NIF. NIFs are not
processes or ports, that you can send a message to. Only function arguments
are passed from Erlang to C.

Also, NIFs are most suitable for synchronous returns.

Theepan



On Tue, Sep 29, 2015 at 8:25 PM, Daniel Goertzen <>
wrote:

> I love the Erlang NIF API, but one thing I’ve missed is a nice way to send
> messages into NIF code. Native Processes could provide that, but for a
> variety of reasons it doesn’t look like that will be implemented any time
> soon. As a stopgap I would like to pitch the idea of “NIF Callback Pids”.
> The idea is that there would be a new NIF API that would create a new PID
> and bind it to a user NIF function. When anything is sent to that pid, the
> user NIF function is executed with the message term as a parameter. It
> would look something like... ErlNifPid enif_make_callback_pid(ErlNifEnv *,
> ErlNifSendCallback *cb, void *data); ... and then the callback would look
> like ... void my_callback(ErlNifEnv *env, ErlNifCBEvent event, ERL_NIF_TERM
> msg, void *data) { if(event == Message) { ... handle message, parse and
> post to thread, etc } else if(event == Destroy) { ... free private data } }
> This would give NIF modules the power to emulate processes in a very
> flexible way. A typical application would parse the message term and post a
> C struct to a thread. A single thread could possibly represent many
> callback pids. Or for certain applications, a thread may not be needed at
> all. So, I’ve been reading VM code to see how this might be implemented,
> but before I get too far I should ask… 1. Has anyone explored this already?
> 2. Is the idea fundamentally broken is some way that would prevent it from
> ever working? 3. Does anyone other than me think this would be useful?
>
>
> Thanks,
>
> Dan.
>
>
>
> _______________________________________________
> 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/20150929/7d692ed3/attachment.html>


More information about the erlang-questions mailing list