[erlang-questions] Proper way to run C code without crashing the VM

Dmytro Lytovchenko <>
Wed Aug 16 15:58:46 CEST 2017


When the stability is important you have several choices:
1. Not use a NIF, write your logic in Erlang. Big industrial Erlang users
may prefer this, for better debuggability and predictability at the cost of
performance.
2. Write a really safe NIF which doesn't crash. Use defensive programming
approach. Use safe language like Rust.
3. Separate your C code from Erlang node, write a port — a console
application which accepts input in stdin and prints results to stdout, then
use Erlang open port function to start it and port commands to communicate
with it.

2017-08-16 15:53 GMT+02:00 code wiget <>:

> Hello,
>
> I have been reading about NIF’s here: http://erlang.org/doc/
> tutorial/nif.html but it seems like they are incredibly unsafe: “it is
> also the least safe, because a crash in a NIF brings the emulator down
> too”. The problem here is huge, ideally I can’t ever have my Erlang VM
> close.
>
> What solution do you Erlangers use when you have to run low level code? My
> goal is to send a sort of “GET” request with a UUID and I will receive back
> that UUID along with some binary values. My C code works with this, but I
> can’t jeopardize the entire server crashing.
>
> Thank you for your help!
>
> _______________________________________________
> 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/20170816/2f92c3db/attachment.html>


More information about the erlang-questions mailing list