GNOME Bugzilla – Bug 711839
Add Glib::MainContext::invoke() wrapper
Last modified: 2021-07-05 12:22:09 UTC
We should have this in the bindings. See the commit log for more information.
Created attachment 259554 [details] [review] Add Glib::MainContext::invoke() wrapper Modern GLib is trying to phase out GMainLoop in favour of GMainContext, especially when it comes to threads usage. The invoke() method of GMainContext is used in two cases: • if the code is using (native) threads with multiple main contexts and wishes to invoke a callback function in the correct context, which is the case with GIO • if the code is using an API that explicitly breaks when used from multiple threads, and requires that each callback is invoked a specific main context, which is the case of GTK+ The usual way to perform this operation before the introduction of the g_main_context_invoke() function was to schedule an idle source; this requires setting up idle sources for specific contexts (thus foregoing all the convenience API). Given that the documentation for the libraries based on GLib is starting to point in the direction of g_main_context_invoke(), the Perl bindins should provide a wrapper for this function.
The patch looks good to me (apart from some minor spaces-vs-tabs issues), but it needs some unit tests. Also, as far as I can see, this would suffer from the same kinds of problems that the Glib::Idle approach has when used by Perl code running in different threads: If you call $context->invoke() from some thread on a context not attached to that thread, then gperl_main_context_invoke_callback() will access SV* pointers from the calling thread in the context's thread, i.e. it will try to use SV* pointers belonging to one Perl interpreter instance with another Perl interpreter instance. This is unreliable. This is not an argument against the patch, however.
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME?utf8=%E2%9C%93&filter=perl- Thank you for your understanding and your help.