<div dir="ltr">Thu May 23 20:42:37 CEST 2019 Sverker Ericsson wrote:<br>> On tor, 2019-05-23 at 15:54 +0200, Mikael Karlsson wrote:<br>>> Hi,<br>>> I just started to write some nif code to interface towards a Linux driver API.<br>>> I can install a callback function in my nif module that gets called from the<br>>> driver  whenever it is ready to receive new data. Currently it gets called<br>>> every 5 ms. The callback function sends a message to an erlang process that in<br>>> turn delivers new data to the driver. (Using another nif function).<br>>><br>>> This works, although I am a bit puzzled how, since the callback function that<br>>> is called from the linux driver appearantly is running outside the Erlang VM<br>>> and still is able to send a message to the erlang process. Could anyone<br>>> explain how this works?<br>>><br><br>> If your callback function calls enif_send to send the message and the message<br>> arrives, then apparently it's running within the Erlang VM.<br>><br>> If in doubt:<br>> 1. Enable core dump generation (ulimit -c, /proc/sys/kernel/core_pattern, etc).<br>> 2. Put a call to abort() in your callback.<br>> 3. Run and watch your beam.smp crash.<br>> 4. Do post mortem with "gdb beam.smp <core-dump>"<br>> 5. Use 'backtrace' command to see who is calling you.<br><br>> /Sverker<div><br></div><div>Thanks,</div><div>I am using enif_send and I realise that it is running within the VM (beam.smp) process now.<br></div><div>And it works fine even though I am still wondering how the asynchronous notification plays together with the Erlang scheduling, or maybe it doesn't need to, but just works anyway.</div><div><br></div><div>Mikael</div><div><br></div></div>