You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I've opened this PR to see what it would take to make the handles Send + Sync, which would be somewhat possible on macOS, iOS and the web (provided that users uphold the "only use this on the main thread" requirement, which one could argue might be a safety footgun) - though I'm unsure if it's actually safe on the other platforms?
In any case we need to do something, because winit::Window is Send + Sync, and it unconditionally implements HasWindowHandle, so users could always just send the window to another thread and get a handle from that.
We had a lengthy discussion with @daxpedda on matrix, and I believe we end up with a solution different to what you propose.
The thing is that we must not mark it as a Send + Sync, since it's a footgun, and in reality it's not a Send + Sync on all the platforms. We can mark individual handlers as Send + Sync, but we can't guarantee that the handler will be Send + Sync all the time.
In any case we need to do something, because winit::Window is Send + Sync, and it unconditionally implements HasWindowHandle, so users could always just send the window to another thread and get a handle from that.
The solution to that was to get rid of the handler traits or split getting a handlers out of some pseudo struct (has no use other than give you handle based on thread). In the end, what winit will have is a regular raw_window_handle getter, but which will fail if you call to it
on a thread other than event loop's thread, and an unsafe method, which will work, but at least there will be an attempt to deliver what you need to do and it'll that, while you have handler, normal reading/writing won't work like on the main thread, and you'll need extra sync.
Also, making something Send and Sync when in reality they are not doesn't make any sense, because users can clearly just wrap the type and send across the thread boundaries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugSomething isn't workingenhancementNew feature or request
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
winitwe're currently discussing this, both in rust-windowing/winit#3136 and on Matrix. See also previous discussion in #59, and the related issue in #85.So I've opened this PR to see what it would take to make the handles
Send + Sync, which would be somewhat possible on macOS, iOS and the web (provided that users uphold the "only use this on the main thread" requirement, which one could argue might be a safety footgun) - though I'm unsure if it's actually safe on the other platforms?In any case we need to do something, because
winit::WindowisSend + Sync, and it unconditionally implementsHasWindowHandle, so users could always just send the window to another thread and get a handle from that.Fixes #85 and fixes #147.
TODO: