Skip to content
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

Make Window !Send + !Sync #3435

Open
madsmtm opened this issue Jan 27, 2024 · 2 comments
Open

Make Window !Send + !Sync #3435

madsmtm opened this issue Jan 27, 2024 · 2 comments
Labels
C - needs discussion Direction must be ironed out S - api Design and usability

Comments

@madsmtm
Copy link
Member

madsmtm commented Jan 27, 2024

Part of #3367, opening to discuss separately.

We've worked hard on trying to make Window safely Send + Sync, but this somewhat obscures what's really happening underneath the hood: Some backends use Mutex, others like macOS/iOS dispatch the events to the main thread (and you may even deadlock if you try to use the window from a thread while the event loop is not running).

So maybe this is actually the wrong solution, and windows should not actually be Send + Sync? Though if we remove it, we'll still have to find some way of allowing users to render on different threads.

Are there other use-cases for Send + Sync windows (other than rendering)?

Related: #3317, #3434.

@madsmtm madsmtm added S - api Design and usability C - needs discussion Direction must be ironed out labels Jan 27, 2024
@madsmtm madsmtm changed the title Make Window not Send + Sync? Make Window !Send + !Sync Jan 27, 2024
@madsmtm madsmtm added this to the Version 0.31.0 milestone Jan 27, 2024
@daxpedda
Copy link
Member

Are there other use-cases for Send + Sync windows (other than rendering)?

It is still highly desirable for MT applications to be able to call all sort of Window methods in different threads.
The go-to suggestions to solve this is a WindowHandle::queue() method that basically works like the abstraction used in iOS/MacOS/Web right now: just package a closure that will be executed on the event loop.

Backends that do support certain methods to be called in any thread will have to do that via extension.

@kchibisov
Copy link
Member

I think we should just have a WindowHandle implementing Window more or less generically with the help of the queue, however certain backends may overwrite methods they can dispatch straight away. It's a bit more work, but no need to separate functionality, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - needs discussion Direction must be ironed out S - api Design and usability
Development

No branches or pull requests

3 participants