[erlang-questions] How to properly stop complicated async NIF resource.

Max Lapshin max.lapshin@REDACTED
Wed Jul 17 17:52:54 CEST 2019


Hi.

We are writing NIF wrapper for OpenMAX — standard API for transcoding video
on Android or Raspberry Pi.

This API requires to launch separate thread (launched by library) and this
thread receives some events from hardware. This thread wraps hardware
events in erlang messages and sends them to owner process.  All this looks
really cool and we have excellently working happy path of code.

When whole resource is to be destroyed, we need to clean it properly,
shutdown all opened hardware handlers. Right now we have to write
complicated code on C in destructor that calls cond_wait, mutex_lock, etc.

The same code in erlang is 100 times cleaner and easier, however in
destructor we cannot write in erlang.  I cannot exit from destructor
function and ask to continue destructing when separate thread will be
activated by hardware.

So it would be cool to continue having erlang vm even in destructor or make
something like "delayed destructor" with "I promise to finish this
destruction".

Question is: is my problem well known or it is very specific?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190717/a980268c/attachment.htm>


More information about the erlang-questions mailing list