New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: syscall: ReleaseCallback for Windows #46184
Comments
cc @alexbrainman @mattn @zx2c4 @gopherbot add OS-Windows |
What should happen if a released callback is called? |
Just panic, maybe? This should be the same situation as calling a released |
Why do you need new I don't see any use for Thank you. Alex |
My understanding is that there is a limit for the number of the callbacks. If the number of calls of NewCallback reaches the limit, you can no longer create a new callback. Is that correct? Or, at least, I'd want the documentation to make it explicit that a callback created by NewCallback is never released. |
Actual example is |
You're best off having one global callback for that, and using the dwInstance field in order to index into a map of actual callbacks. (Alternatively, that function takes an event handle instead.) |
I agree that
(2) Is the case I'm worried about, because we can't really detect it and panic, at least not the way callbacks are implemented today. There might be some way to work around this, though. The limitation today stems from the fact that we identify the slot based on the return PC passed into |
I would do what @zx2c4 suggested in #46184 (comment). I think one callback function should be enough in your scenario. I also share @ianlancetaylor (#46184 (comment)) and @mknyszek (#46184 (comment)) concerns. There is no general way to inform external code to stop calling your callback function before you release it. This will cause memory corruption and crashes. It is not worth the trouble. Alex |
Change https://golang.org/cl/321133 mentions this issue: |
I think this is the same situation as Based on #46184 (comment), I'm now convinced that implementing |
This proposal has been added to the active column of the proposals project |
Currently NewCallback and NewCallbackCDecl may only be called a limited number of times in a single Go process, but this property of the API is not documented. This change fixes that, but does not document the precise limit to avoid making that limit part of the API, leaving us open to increasing or decreasing the limit in the future as needed. Although the API avoids documenting a limit, it does guarantee a minimum callback count so users can rely on at least some amount of callbacks working. Updates #46184. Change-Id: I5129bf5fe301efff73ac112ba1f207ab32058833 Reviewed-on: https://go-review.googlesource.com/c/go/+/321133 Trust: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
ReleaseCallback
for Windows
So it sounds like we should not add ReleaseCallback then? |
I don't think we should not, but I'm not sure how feasible this would be. @mknyszek what do you think? |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
Now a callback generated by
syscall.NewCallback
orsyscall.NewCallbackCDecl
is never released based on the current implementation (especiallyruntime/syscall_windows.go
).My understanding is that it is hard or impossible to release them automatically. Would it be possible to have a function to release a callback like
ReleaseCallback
? Or, what about changing the return type ofNewCallback
to a new typeCallback
and letting it haveRelease
function?CC @mknyszek
The text was updated successfully, but these errors were encountered: