<div dir="ltr">Hi.<div><br></div><div>We are writing NIF wrapper for OpenMAX — standard API for transcoding video on Android or Raspberry Pi.</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>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".</div><div><br></div><div>Question is: is my problem well known or it is very specific?</div><div><br></div></div>