Continuing the discussion from My gamedever wishlist for Rust:
[quote=“tomaka, post:1, topic:2859, full:true”]
No way to detect at compile-time whether we are in the main thread. This one is a bit weird, but on OS/X some GUI operations can only be done in the main thread. It would be nicer if this was detectable at compile-time.[/quote]
This probably deserves its own topic. How do you define the main thread and what kind of compile-time support would you expect?
In the Gtk-rs project we have a similar requirement to uphold:
You should only use GTK+ and GDK from the thread
gtk_main()were called on. This is usually referred to as the “main thread”.
Enforcing this statically would probably mean that
gtk_init should return a
!Send + !Sync struct and any other object constructors take a reference to it (or a clone) as a parameter to prevent creation of, say, a window in another thread. https://github.com/gtk-rs/gtk/issues/3 has links to more discussions. We haven’t acted on this yet.