GNOME Bugzilla – Bug 765173
documentation of g_main_context_push_thread_default() regarding GIO run_in_thread() ops
Last modified: 2016-05-08 12:12:57 UTC
The documentation of g_main_context_push_thread_default() says: "Normally you would call this function shortly after creating a new thread, passing it a GMainContext which will be run by a GMainLoop in that thread, to set a new default context for all async operations in that thread. (In this case, you don't need to ever call g_main_context_pop_thread_default().)" But, if the user runs e.g. g_simple_async_result_run_in_thread() passing a thread function where a new main context is created and pushed as thread default, the user MUST g_main_context_pop_thread_default() before exiting the thread function, or the GMainContext that was queued up in the internal GPrivate will never be released. This is because g_simple_async_result_run_in_thread() and g_task_run_in_thread() use a GThreadPool, and so the threads are re-used automatically in the run_in_thread() operations. In my personal case, an application that runs test cycles, each in a g_simple_async_result_run_in_thread() call (with a thread function NOT calling g_main_context_pop_thread_default()), ended up crashing with "too many open file descriptors" because the fds of the GWakeups created within the GMainContext were never closed. My suggestion here is to reword a bit the g_main_context_push_thread_default() documentation, patch following.
Created attachment 326188 [details] [review] suggested patch
Comment on attachment 326188 [details] [review] suggested patch sure
Pushed to git master.