NIF for porting my multithreaded C ++ code

I have C ++ code that implements a special protocol through a serial port. The code is multi-threaded and internally polled by the serial port and performs its cyclic processing. I would like to name this driver from erlang, and also receive events from this driver. My concern is that this C ++ code is multi-threaded, as well as statefull, which means that when a certain function is called in the driver, it caches everything inside, which will be used / required for subsequent calls to the driver. My questions

1. Does NIF go in the same os process as my other erlang processes or does NIF run in a separate os process?

2. Does it make sense to deform this multi-threaded C ++ code with NIF support?

4. If NIF is not suitable, the best way for me is to make Elrang speak back and forth with this C ++ code. I also prefer that my C ++ code be inside the same OS process as the rest of my Erlang processes, and since it seems like related drivers are an option, but are not sure the multi-threaded nature of my code in C ++ will be fine model. Plus, I heard that they can ruin the elrang scheduler?

+5
source share
1 answer
  • Unlike ports, NIFs run in the Erlang VM process, similar to drivers. Because of this, any NIF failures will also lead to VM rollback. And, answering in advance, to your last question, NIF, for example, drivers, can block your scheduler.

  • , ++. - 1) , , concurrency ++, . , . , , , 1- , , .

  • , (, , NIF). ++, Erlang.

NIF , , ( , ). ( , ).

: http://www.erlang.org/doc/apps/erts/driver.html

- (. ) NIF: http://www.erlang.org/doc/tutorial/nif.html

+4

All Articles