diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go index 6bd719f54..7ad482a05 100644 --- a/src/runtime/runtime.go +++ b/src/runtime/runtime.go @@ -106,6 +106,25 @@ func UnlockOSThread() { // point of the call. func KeepAlive(x interface{}) +// AddCleanup is a dummy cleanup implementation. It doesn't do any cleaning up. +// +// We base this on the following loophole in the official runtime.AddCleanup +// documentation: +// +// > The cleanup(arg) call is not always guaranteed to run; in particular it is +// > not guaranteed to run before program exit. +// +// So it's technically correct (the best kind of correct) to not run any +// cleanups. But of course, this can lead to resource leaks so cleanups may need +// to be implemented eventually. +func AddCleanup[T, S any](ptr *T, cleanup func(S), arg S) Cleanup { + return Cleanup{} +} + +type Cleanup struct{} + +func (c Cleanup) Stop() {} + var godebugUpdate func(string, string) //go:linkname godebug_setUpdate internal/godebug.setUpdate