[J3] Finalization Question
Malcolm Cohen
malcolm at nag-j.co.jp
Sat May 28 01:01:38 UTC 2022
Hi Vipul,
You are quite right, ERROR STOP works for that purpose.
(I started to write my reply before your message arrived, then went off and made the example and tested it, then came back and posted... and then saw your message.)
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Vipul Parekh via J3
Sent: Friday, May 27, 2022 9:51 PM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Vipul Parekh <parekhvs at gmail.com>
Subject: Re: [J3] Finalization Question
On Fri, May 27, 2022 at 12:53 AM Malcolm Cohen via J3 <j3 at mailman.j3-fortran.org <mailto:j3 at mailman.j3-fortran.org> > wrote:
..
A specification function is what you are looking for here. However, such a function must be pure, and so the final subroutine must be pure, and therefore cannot set a global variable or print a message, so it can be hard to tell whether it ran. If your compiler supports memory allocation tracing, you can use pointer components to observe that yes, the final subroutine does get executed (unless the compiler has a bug!). Or if the compiler does not support memory allocation tracing, you could allocate a 500MB array component in the function (and deallocate it in the finaliser!) and run it a million times to check that you don't run out of virtual memory (or you are on a 500TB machine).
Starting Fortran 2018, one can employ the ERROR STOP statement as a way to determine whether the final procedure was invoked.
The example I showed in my previous note in this thread indeed makes use of this facility.
Vipul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20220528/d132285e/attachment.htm>
More information about the J3
mailing list