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

Ensure that OS/X window creation is done in the main thread #47

Closed
tomaka opened this issue Oct 6, 2014 · 7 comments
Closed

Ensure that OS/X window creation is done in the main thread #47

tomaka opened this issue Oct 6, 2014 · 7 comments

Comments

@tomaka
Copy link
Contributor

tomaka commented Oct 6, 2014

Either fail if not on the main thread, or redirect the creation to the main thread somehow. The second solution is preferred.

cc #4

@tomaka tomaka added bug labels Oct 6, 2014
@tomaka
Copy link
Contributor Author

tomaka commented Oct 7, 2014

For the moment I think that we should call pthread_main_np (see this) when creating a window, and return an Err if not on the main thread.

@tomaka
Copy link
Contributor Author

tomaka commented Oct 7, 2014

I'm not even sure that you can't bypass the restrictions.

@ghost
Copy link

ghost commented Oct 7, 2014

We need to create some bindings with the GCD framework to execute code on the main thread.
(https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/index.html)

You can assign me for this task.

@tomaka tomaka assigned tomaka and unassigned tomaka Oct 25, 2014
@fkaa
Copy link
Contributor

fkaa commented Apr 24, 2015

@DavidPartouche will https://github.com/SSheldon/rust-dispatch enable us to do this?

@tomaka
Copy link
Contributor Author

tomaka commented May 16, 2015

@SSheldon In my opinion we should just detect whether we're in the main thread when creating a window, and panic if it's not the case.

Ultimately the main window constructor should do the same check, whatever the platform is.

@SSheldon
Copy link
Contributor

@tomaka there's also an issue that we can't poll for events on multiple threads; that should probably just be handled by the main thread.

While the Application Kit continues to work if other threads are involved in the event path, operations can occur out of sequence. For example, if two different threads are responding to key events, the keys could be received out of order. By letting the main thread process events, you achieve a more consistent user experience. Once received, events can be dispatched to secondary threads for further processing if desired.

I think that, with the current event iterators, another window's iterator might receive your event and then it doesn't know what to do with it.

This could potentially be solved by the main thread polling for events and then dispatching them to the appropriate window. That's where my suggestion of a glutin_main came from. Would a requirement that users must call glutin_main at the end of their main method make sense in other APIs besides Cocoa?

@tomaka
Copy link
Contributor Author

tomaka commented Nov 3, 2016

Closing in favor of rust-windowing/winit#31

@tomaka tomaka closed this as completed Nov 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants