GNOME Bugzilla – Bug 547837
g_thread_create() aborts on out-of-memory instead of raising GError
Last modified: 2011-09-30 03:59:29 UTC
When the system doesn't have enough memory to create a thread, Thread::create aborts, with the following output: GThread-ERROR **: file /build/buildd/glib2.0-2.16.4/gthread/gthread-posix.c: line 367 (g_thread_create_posix_impl): error 'Cannot allocate memory' during 'pthread_create' aborting... Instead, according to the documentation, it should raise a ThreadError exception. glibmm version: 2.16 glib version: 2.16 Sample code attached.
Created attachment 116612 [details] Sample code
Created attachment 120920 [details] test.c A C test case. This shows that no GError is raised in this case, though the documentation http://library.gnome.org/devel/glib/stable/glib-Threads.html#g-thread-create does say that errors will be reported via the error output variable. I guess that out-of-memory errors are generally not handled by glib, but I will let the glib developers say for sure.
pthread_create can return ENOMEM but the glib POSIX wrapper only handles EAGAIN gracefully, aborting on any other retval by calling posix_check_err (ret, "pthread_create"); the pthread_create manpage only mentions EAGAIN so that may be a cause for the omission.
May this be intentional just as terminating the app when g_malloc() fails is? From the GLib docs' Memory Allocation section: "If any call to allocate memory fails, the application is terminated"
if this is a feature or GLib policy please close as WONTFIX :)
The original error was reported for glibmm. If glibmm follows glib policy, then there's a bug in the documentation, so the solution is not "WONTFIX".
I agree that documentation for both glibmm and glib need adjusting for this case, I was referring to WONTIFx in case this non-handling is deliberate in glib code.