-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Multi-threaded #205
Comments
I can't speak for other backends, but at least for Web this isn't possible (without a custom wire implementation which comes with significant overhead). This introduces the problem of cross-platform compatibility, either all backends have to be |
Hmm... In However, I can see why it would be undesirable to have different trait implementations on different platforms. |
As a maintainer of the Web backend I'm fine with going down that route as well. |
For Windows and macOS this would require a significant reworking of how the backends work. (In a future release |
You mean |
@notgull so to be fully clear, this is a platform limitation, and will likely not be changed by the softbuffer team? |
Raymond Chen confirms that device contexts can't be sent between threads. To quote:
Essentially, a DC is A similar conundrum affects window handles in I think something similar happens with macOS, but we should check with @madsmtm about that. X11 is perfectly thread safe, by the way, and could be |
On macOS, the window handle is basically an The rendering can be done from another thread though, i.e. I'm fairly sure the |
I'd be alright with |
@notgull what makes it impossible? Also, would that overhead exist even if only that singular message is required? I.e. only |
Unlike macOS, Windows doesn't have a singular "run this function on the GUI thread" function. The intended solution is to post a message to the window which will then be processed on the window's main thread. The problem is that the message is intended to be handled by the window's The intended solution to this is subclassing, where a second |
Actually, this would be 100% safe if it were guaranteed that the |
Very nice. |
Thanks! |
@notgull now that that's merged, are we any further to multi-threaded support? |
Previously, types in softbuffer were !Send and !Sync. However it would be nice if types could be shared across threads. Therefore I've made the following changes: - Context<D> is Send+Sync iff D is Send+Sync - Surface<D, W> is Send iff D is Send+Sync and W is Send - Buffer<'x, D, W> is Send iff D if Send+Sync and W is Send Materially, I've made the following changes across the backends: - X11, Wayland and KMS use Arc for their displays instead of Rc. - MacOS uses MainThreadBound to secure windowing resources. This restriction was already implicitly enforced anyhow. - Windows uses a subclassing strategy to manage creating and destroying resources. This subclass is applied to windows that are registered into softbuffer, and is then used to manage resources. Closes #205 Signed-off-by: John Nunley <dev@notgull.net>
I've filed a PR, but it needs more testing |
Previously, types in softbuffer were !Send and !Sync. However it would be nice if types could be shared across threads. Therefore I've made the following changes: - Context<D> is Send+Sync iff D is Send+Sync - Surface<D, W> is Send iff D is Send+Sync and W is Send - Buffer<'x, D, W> is Send iff D if Send+Sync and W is Send Materially, I've made the following changes across the backends: - X11, Wayland and KMS use Arc for their displays instead of Rc. - MacOS uses MainThreadBound to secure windowing resources. This restriction was already implicitly enforced anyhow. - Windows creates a thread specifically for allocating and then deallocating device contexts. This lets us get around the thread affinity problem. Closes #205 Signed-off-by: John Nunley <dev@notgull.net> Co-authored-by: Mads Marquart <mads@marquart.dk>
Currently,
Context
andSurface
are neitherSend
norSync
. What is the reason for this decision? Is it possible to make them at leastSend
, so they could be madeSync
with aMutex
?The text was updated successfully, but these errors were encountered: