I'm starting to work on a large rework of the wayland backend (again!) to port it to the new wayland-client API, hopefully simplifying it a little in the process.
Now, There is a question that it raises for me: what constraints do we put on whether Window and EventsLoop are Send and or Sync ?
I've seen at some point a test to ensure that EventsLoop was Send + Sync, but it seems this test has been removed now. Overall, I see at least some backends are Send + Sync, but with the numerous API changes that occurred during the last months, I've lost track of this point.
So:
Window supposed to be Send and/or Sync ?EventsLoop supposed to be Send and/or Sync ?If winit should always behave consistently across platforms, EventsLoop really should not be Sync or Send due to macos' requirement of polling/waiting on events on the main thread (at least, I never worked out a nice way around this). I'd go as far as making EventsLoop main-only if there was some way to do so. I'm less sure about the behaviour for Windows.
I don't think there's a good reason for it to be Sync; this substantially complicates implementation for little practical benefit. IIRC we've discussed this before and came to the same conclusion.
I currently I rely on Send for EventsLoop.
@alexheretic could you elaborate on your use case for EventsLoop being Send?
Sure, I have a separate compute and render threads which don't block each other. Since compute processes events, EventsLoop is sent away from Window which resides on the render thread.
Without it I'd have to process events on, and presumably delayed by, the rendering thread and send the events over to the compute, which would be much more of a pain for me.
@alexheretic So, I guess having for example, the EventsLoop not Send, but the Window being Send would work for you as well?
@vberger Yes I believe so.
So, I tend to lean that way too. Currently with wayland, all is Send+Sync, but it substantially complicates the implementation (and will be even more problematic if I try to upgrade to the next version of wayland-client).
Given what @mitchmindtree said, it appears there are platforms for which having the EventsLoop being Send and/or Sync is a complicated matter.
I'd argue that being consistent across platforms is important, and that in this case we should impose that EventsLoop is !Send and !Sync (possibly via a PhantomData marker, or something like that).
On the other hand, if this is chosen, this means that we need to make Window at least Send, if possible.
Done in #322 .
Most helpful comment
So, I tend to lean that way too. Currently with wayland, all is Send+Sync, but it substantially complicates the implementation (and will be even more problematic if I try to upgrade to the next version of wayland-client).
Given what @mitchmindtree said, it appears there are platforms for which having the
EventsLoopbeingSendand/orSyncis a complicated matter.I'd argue that being consistent across platforms is important, and that in this case we should impose that
EventsLoopis!Sendand!Sync(possibly via a PhantomData marker, or something like that).On the other hand, if this is chosen, this means that we need to make
Windowat leastSend, if possible.