RE: Are NIF resources meant to be destroyed immediately on GC?
Sverker Eriksson <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <AM7PR07MB6900723B5F1DA8583DA723EAFDFB0@AM7PR07MB6900.eurprd07.prod.outlook.com> |
From: Sean Hinde <[email protected]> Sent: den 24 november 2020 19:16 To: Sverker Eriksson <[email protected]> Cc: Erlang Questions <[email protected]> Subject: Re: Are NIF resources meant to be destroyed immediately on GC? On 23 Nov 2020, at 23:16, Sverker Eriksson <[email protected] <mailto:[email protected]> > wrote: Prior to OTP 22.0 resource destructors were called directly by the thread that happened to decrease the reference counter down to zero. From OTP 22.0 resource destructors are scheduled. This in order to ensure a stable known execution context for the destructor callback. So it may not have executed when erlang:garbage_collect returns, but will very soon (unless you have a very overloaded system or a bug preventing ref counter from reaching zero). /Sverker, Erlang/OTP This a really nice change. It opens the door to resource destructors being safe for closing external resources like database handles that might take a while. Super cool! Sorry to disappoint, but no. By "scheduled" I just meant "put in run queue to be executed at a later time". Destructors are still executed by a normal scheduler threads and not dirty schedulers. /Sverker
smime.p7s
(application/pkcs7-signature, 5.4 KB) - not displayed