Skip to content

Commit 87bed71

Browse files
committed
runtime: implement dummy AddCleanup
1 parent 63ff828 commit 87bed71

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/runtime/runtime.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ func UnlockOSThread() {
106106
// point of the call.
107107
func KeepAlive(x interface{})
108108

109+
// AddCleanup is a dummy cleanup implementation. It doesn't do any cleaning up.
110+
//
111+
// We base this on the following loophole in the official runtime.AddCleanup
112+
// documentation:
113+
//
114+
// > The cleanup(arg) call is not always guaranteed to run; in particular it is
115+
// > not guaranteed to run before program exit.
116+
//
117+
// So it's technically correct (the best kind of correct) to not run any
118+
// cleanups. But of course, this can lead to resource leaks so cleanups may need
119+
// to be implemented eventually.
120+
func AddCleanup[T, S any](ptr *T, cleanup func(S), arg S) Cleanup {
121+
return Cleanup{}
122+
}
123+
124+
type Cleanup struct{}
125+
126+
func (c Cleanup) Stop() {}
127+
109128
var godebugUpdate func(string, string)
110129

111130
//go:linkname godebug_setUpdate internal/godebug.setUpdate

0 commit comments

Comments
 (0)