After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 765173 - documentation of g_main_context_push_thread_default() regarding GIO run_in_thread() ops
documentation of g_main_context_push_thread_default() regarding GIO run_in_th...
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gthread
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2016-04-17 11:05 UTC by Aleksander Morgado
Modified: 2016-05-08 12:12 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
suggested patch (2.04 KB, patch)
2016-04-17 11:06 UTC, Aleksander Morgado
accepted-commit_now Details | Review

Description Aleksander Morgado 2016-04-17 11:05:06 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.
Comment 1 Aleksander Morgado 2016-04-17 11:06:29 UTC
Created attachment 326188 [details] [review]
suggested patch
Comment 2 Dan Winship 2016-05-03 18:14:35 UTC
Comment on attachment 326188 [details] [review]
suggested patch

sure
Comment 3 Aleksander Morgado 2016-05-08 12:12:57 UTC
Pushed to git master.