diff options
author | Ryan Lortie <desrt@desrt.ca> | 2011-10-13 01:00:57 -0400 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2011-10-13 01:00:57 -0400 |
commit | 430c5635f245ca485f09035f1b6c3a59dd69758c (patch) | |
tree | a3b745d9c991565a087d157522ebf3b3175497e6 /glib/gthread.c | |
parent | 015f4b4513279c4be40c03121473ffcea347ed84 (diff) | |
download | glib-430c5635f245ca485f09035f1b6c3a59dd69758c.tar.gz |
g_thread_new: never fail
Remove the GError argument from g_thread_new() and abort on failure.
Introduce g_thread_try() for those who want to handle failure.
Diffstat (limited to 'glib/gthread.c')
-rw-r--r-- | glib/gthread.c | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/glib/gthread.c b/glib/gthread.c index 1567b5faf..2cdac5354 100644 --- a/glib/gthread.c +++ b/glib/gthread.c @@ -731,17 +731,48 @@ g_thread_proxy (gpointer data) * a debugger. Some systems restrict the length of @name to * 16 bytes. * - * @error can be %NULL to ignore errors, or non-%NULL to report errors. - * The error is set, if and only if the function returns %NULL. + * If the thread can not be created the program aborts. See + * g_thread_try() if you want to attempt to deal with failures. * - * You must + * Returns: the new #GThread + * + * Since: 2.32 + */ +GThread * +g_thread_new (const gchar *name, + GThreadFunc func, + gpointer data) +{ + GError *error = NULL; + GThread *thread; + + thread = g_thread_new_internal (name, g_thread_proxy, func, data, 0, &error); + + if G_UNLIKELY (thread == NULL) + g_error ("creating thread '%s': %s", name ? name : "", error->message); + + return thread; +} + +/** + * g_thread_try: + * @name: a name for the new thread + * @func: a function to execute in the new thread + * @data: an argument to supply to the new thread + * @error: return location for error + * + * This function is the same as g_thread_new() except that it allows for + * the possibility of failure. + * + * If a thread can not be created (due to resource limits), @error is + * set and %NULL is returned. * * Returns: the new #GThread, or %NULL if an error occurred * * Since: 2.32 */ GThread * -g_thread_new (const gchar *name, +g_thread_try (const gchar *name, GThreadFunc func, gpointer data, GError **error) @@ -749,6 +780,7 @@ g_thread_new (const gchar *name, return g_thread_new_internal (name, g_thread_proxy, func, data, 0, error); } + /** * g_thread_new_full: * @name: a name for the new thread |