GNOME Bugzilla – Bug 775171
glcontext/glwindow: Race when creating/quitting
Last modified: 2016-11-28 03:28:49 UTC
This is the core issue exposed by the various hanging gl unit tests The "easiest" to trigger the issue is test_is_shared. The problem is the following: 1) A context is created 2) It creates/starts a thread 2.1) That thread asks for _unlock_create_thread() to be called 2.2) Then calls gst_gl_window_run which will eventually start a mainloop 3) In the meantime the context is finalized 3.1) We call gst_gl_window_quit which will stop the mainloop ... ... but that mainloop hasn't started yet ! 3.2) It unlocks the render_lock and joins the thread 2.3) The other thread finally calls main_loop_run ... ... hang Something is needed to avoid that race, but i'm not 100% sure yet.
This is due to 626bcccff96f624f59c5212b3e21e472240171fd removing locks on shutdown and the previous fix 2776cef25d2a98668b73272aecfe77e684e6627e not adding them back correctly.
The other failure case in the new code with g_thread_join() is if the last ref is held by the GL thread. Then g_thread_join() that will fail.
The second problem is that the g_main_context_push_thread_default() in 072183ce616760c8859d5c14f3a440be003891bf makes the g_main_context_invoke() in gst_gl_window_send_message_async() run the function immediately rather than deferring it until later as is required to have the loop running before returning from gst_gl_context_create().
commit 024e92afe7bb6ab019876ceeb97041129b95c0d7 Author: Matthew Waters <matthew@centricular.com> Date: Mon Nov 28 14:22:05 2016 +1100 glwindow: move g_main_context_push/pop_thread_default() to run() Calling g_main_context_push_thread and then g_main_context_invoke() (used by gst_gl_window_send_message_async()) in the same thread will cause the invoked function to run immediately instead of being delayed. This had implications for the creation of the OpenGL context not waiting until the main loop had completely started up and as a result would sometimes deadlock in short create/destroy scenarios. https://bugzilla.gnome.org/show_bug.cgi?id=775171 commit 25fbc6d877b81fb5cd2731edc01d05bf900420dc Author: Matthew Waters <matthew@centricular.com> Date: Mon Nov 28 14:19:18 2016 +1100 glcontext: fix race between creation/shutdown 626bcccff96f624f59c5212b3e21e472240171fd removed some locks that allowed the main loop quit to occur before the context was fully created. 2776cef25d2a98668b73272aecfe77e684e6627e attempted to readd them but missed the scop of the quit() call. Also remove the use of g_thread_join() as that's not safe to use when it's possible to lose the last reference from the GL thread. https://bugzilla.gnome.org/show_bug.cgi?id=775171