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 547837 - g_thread_create() aborts on out-of-memory instead of raising GError
g_thread_create() aborts on out-of-memory instead of raising GError
Status: RESOLVED WONTFIX
Product: glib
Classification: Platform
Component: gthread
2.18.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-08-14 20:51 UTC by Henrique
Modified: 2011-09-30 03:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Sample code (352 bytes, text/plain)
2008-08-14 20:52 UTC, Henrique
Details
test.c (414 bytes, text/x-csrc)
2008-10-20 11:59 UTC, Murray Cumming
Details

Description Henrique 2008-08-14 20:51:24 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.
Comment 1 Henrique 2008-08-14 20:52:18 UTC
Created attachment 116612 [details]
Sample code
Comment 2 Murray Cumming 2008-10-20 11:59:34 UTC
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.
Comment 3 Jani Monoses 2008-12-05 14:25:58 UTC
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.
Comment 4 Jani Monoses 2008-12-10 14:26:57 UTC
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"
Comment 5 Jani Monoses 2009-07-07 14:10:28 UTC
if this is a feature or GLib policy please close as WONTFIX :)
Comment 6 Henrique 2009-07-07 14:16:51 UTC
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".
Comment 7 Jani Monoses 2009-07-07 14:28:10 UTC
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.