[J3] [EXTERNAL] Re: Clarification on F18/017
Carlson, Neil
nnc at lanl.gov
Tue Jun 9 09:55:30 EDT 2020
Thomas wrote:
> What is really needed to further the argument is a concrete example in which the undesired order will lead to a surprising (or incorrect) result _beyond_ merely the order being surprising. E.g., some handle to a non Fortran resource is obliterated before the resource is properly released.
Yes, that is exactly the case described at this link already mentioned several times in this thread: https://github.com/j3-fortran/fortran_proposals/issues/146#issuecomment-589857885
But for clarity here is a code skeleton for the described case. Here amrex is a third party library written in C++ that provides a Fortran interface. It is a framework that must be started and stopped and its objects depend on that framework. The amrex-provided class amrex_obj is finalizable. Stopping the framework obliterates resources that its finalizer needs, and so it must be finalized before the framework is stopped.
module m
use amrex_module
type :: amrex_env
contains
final :: finalize_amrex_env
end type
type, extends(amrex_env) :: solver
class(amrex_obj), allocatable :: obj
contains
procedure :: init
end type
contains
subroutine finalize_amrex_env(this)
type(amrex_env), intent(inout) :: this
call amrex_finalize()
end subroutine
subroutine solver_init(this)
class(solver), intent(out) :: this
call amrex_init()
call amrex_alloc_obj(this%obj)
end subroutine
end module
program main
use m
call run
contains
subroutine run
type(solver) :: s
call s%init
end subroutine
end program
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20200609/e69debaf/attachment.htm>
More information about the J3
mailing list