The documentation for runtime.AddCleanup 
<https://pkg.go.dev/runtime#AddCleanup> says:

> There is no specified order in which cleanups will run.

Given the following types:

type Parent struct {
    parentResource int
}

type Child struct {
    parent *Parent
    childResource int
}

and the following code:

parentResource := 0
parent := &Parent{
    parentResource: parentResource,
}
runtime.AddCleanup(parent, func (int) {}, parentResource)
childResource := 1
child := &Child{
    parent: parent,
    childResource: childResource
}
runtime.AddCleanup(child, func(int) {}, childResource)

is it guaranteed that the cleanup for childResource will run before the 
cleanup for parentResource?

Notes:
* I know that the structs here are small enough to be "tiny", but Child 
contains a pointer to Parent so the cleanups should run.
* The example here is for a specific case where the resources are allocated 
by a C library, the child resource is "owned" by the parent, and so it's 
important that the child resource cleanup runs before the parent resource 
cleanup.

Many thanks for any insight!

Tom

The actual code I'm worried about is 
here: 
https://github.com/twpayne/go-geos/pull/183/commits/8ea732a7c65f873d48526cb1574e3c137dd66f74

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/38a31657-5073-46c1-8726-8cec39652dd8n%40googlegroups.com.

Reply via email to