mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-14 19:55:12 +01:00
thread: nuke the concept of 'joinable'
And remove the 'joinable' argument from g_thread_new() and g_thread_new_full(). Change the wording in the docs. Clarify expectations for (deprecated) g_thread_create().
This commit is contained in:
parent
b0e73ca390
commit
015f4b4513
@ -305,7 +305,6 @@ _g_dbus_shared_thread_ref (void)
|
|||||||
data->thread = g_thread_new ("gdbus",
|
data->thread = g_thread_new ("gdbus",
|
||||||
gdbus_shared_thread_func,
|
gdbus_shared_thread_func,
|
||||||
data,
|
data,
|
||||||
TRUE,
|
|
||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
/* We can cast between gsize and gpointer safely */
|
/* We can cast between gsize and gpointer safely */
|
||||||
|
@ -75,7 +75,7 @@ idle_start_test1_thread (gpointer loop)
|
|||||||
gboolean io_completed;
|
gboolean io_completed;
|
||||||
|
|
||||||
g_mutex_lock (&test1_mutex);
|
g_mutex_lock (&test1_mutex);
|
||||||
thread = g_thread_new ("test1", test1_thread, NULL, TRUE, NULL);
|
thread = g_thread_new ("test1", test1_thread, NULL, NULL);
|
||||||
|
|
||||||
g_get_current_time (&time);
|
g_get_current_time (&time);
|
||||||
time.tv_sec += 2;
|
time.tv_sec += 2;
|
||||||
|
@ -943,7 +943,6 @@ test_dispatch (const gchar *object_path)
|
|||||||
thread = g_thread_new ("test_dispatch",
|
thread = g_thread_new ("test_dispatch",
|
||||||
test_dispatch_thread_func,
|
test_dispatch_thread_func,
|
||||||
(gpointer) object_path,
|
(gpointer) object_path,
|
||||||
TRUE,
|
|
||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (thread != NULL);
|
g_assert (thread != NULL);
|
||||||
|
@ -605,7 +605,6 @@ test_peer (void)
|
|||||||
service_thread = g_thread_new ("test_peer",
|
service_thread = g_thread_new ("test_peer",
|
||||||
service_thread_func,
|
service_thread_func,
|
||||||
&data,
|
&data,
|
||||||
TRUE,
|
|
||||||
&error);
|
&error);
|
||||||
while (service_loop == NULL)
|
while (service_loop == NULL)
|
||||||
g_thread_yield ();
|
g_thread_yield ();
|
||||||
@ -1055,7 +1054,6 @@ delayed_message_processing (void)
|
|||||||
service_thread = g_thread_new ("dmp",
|
service_thread = g_thread_new ("dmp",
|
||||||
dmp_thread_func,
|
dmp_thread_func,
|
||||||
data,
|
data,
|
||||||
TRUE,
|
|
||||||
&error);
|
&error);
|
||||||
while (data->server == NULL || !g_dbus_server_is_active (data->server))
|
while (data->server == NULL || !g_dbus_server_is_active (data->server))
|
||||||
g_thread_yield ();
|
g_thread_yield ();
|
||||||
@ -1204,7 +1202,6 @@ test_nonce_tcp (void)
|
|||||||
service_thread = g_thread_new ("nonce-tcp-service",
|
service_thread = g_thread_new ("nonce-tcp-service",
|
||||||
nonce_tcp_service_thread_func,
|
nonce_tcp_service_thread_func,
|
||||||
&data,
|
&data,
|
||||||
TRUE,
|
|
||||||
&error);
|
&error);
|
||||||
while (service_loop == NULL)
|
while (service_loop == NULL)
|
||||||
g_thread_yield ();
|
g_thread_yield ();
|
||||||
@ -1514,7 +1511,6 @@ test_tcp_anonymous (void)
|
|||||||
service_thread = g_thread_new ("tcp-anon-service",
|
service_thread = g_thread_new ("tcp-anon-service",
|
||||||
tcp_anonymous_service_thread_func,
|
tcp_anonymous_service_thread_func,
|
||||||
&seen_connection, /* user_data */
|
&seen_connection, /* user_data */
|
||||||
TRUE, /* joinable */
|
|
||||||
&error);
|
&error);
|
||||||
while (service_loop == NULL)
|
while (service_loop == NULL)
|
||||||
g_thread_yield ();
|
g_thread_yield ();
|
||||||
|
@ -222,7 +222,7 @@ test_proxy (void)
|
|||||||
for (i = 0; i < n_threads; i++)
|
for (i = 0; i < n_threads; i++)
|
||||||
{
|
{
|
||||||
proxy_threads[i] = g_thread_new ("run-proxy",
|
proxy_threads[i] = g_thread_new ("run-proxy",
|
||||||
run_proxy_thread, connection, TRUE,
|
run_proxy_thread, connection,
|
||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
}
|
}
|
||||||
|
@ -568,7 +568,6 @@ on_name_acquired (GDBusConnection *connection,
|
|||||||
g_thread_new ("check-proxies",
|
g_thread_new ("check-proxies",
|
||||||
check_proxies_in_thread,
|
check_proxies_in_thread,
|
||||||
loop,
|
loop,
|
||||||
TRUE,
|
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,6 @@ test_delivery_in_thread (void)
|
|||||||
thread = g_thread_new ("deliver",
|
thread = g_thread_new ("deliver",
|
||||||
test_delivery_in_thread_func,
|
test_delivery_in_thread_func,
|
||||||
NULL,
|
NULL,
|
||||||
TRUE,
|
|
||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (thread != NULL);
|
g_assert (thread != NULL);
|
||||||
@ -398,7 +397,6 @@ test_method_calls_on_proxy (GDBusProxy *proxy)
|
|||||||
thread1 = g_thread_new ("sleep",
|
thread1 = g_thread_new ("sleep",
|
||||||
test_sleep_in_thread_func,
|
test_sleep_in_thread_func,
|
||||||
&data1,
|
&data1,
|
||||||
TRUE,
|
|
||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (thread1 != NULL);
|
g_assert (thread1 != NULL);
|
||||||
@ -411,7 +409,6 @@ test_method_calls_on_proxy (GDBusProxy *proxy)
|
|||||||
thread2 = g_thread_new ("sleep2",
|
thread2 = g_thread_new ("sleep2",
|
||||||
test_sleep_in_thread_func,
|
test_sleep_in_thread_func,
|
||||||
&data2,
|
&data2,
|
||||||
TRUE,
|
|
||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (thread2 != NULL);
|
g_assert (thread2 != NULL);
|
||||||
@ -424,7 +421,6 @@ test_method_calls_on_proxy (GDBusProxy *proxy)
|
|||||||
thread3 = g_thread_new ("sleep3",
|
thread3 = g_thread_new ("sleep3",
|
||||||
test_sleep_in_thread_func,
|
test_sleep_in_thread_func,
|
||||||
&data3,
|
&data3,
|
||||||
TRUE,
|
|
||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (thread3 != NULL);
|
g_assert (thread3 != NULL);
|
||||||
|
@ -201,7 +201,13 @@ start_sync_lookups (char **argv, int argc)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
g_thread_new ("lookup", lookup_thread, argv[i], FALSE, NULL);
|
{
|
||||||
|
GThread *thread;
|
||||||
|
|
||||||
|
thread = g_thread_new ("lookup", lookup_thread, argv[i], NULL);
|
||||||
|
g_assert (thread != NULL);
|
||||||
|
g_thread_unref (thread);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -90,8 +90,12 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
if (cancel_timeout)
|
if (cancel_timeout)
|
||||||
{
|
{
|
||||||
|
GThread *thread;
|
||||||
|
|
||||||
cancellable = g_cancellable_new ();
|
cancellable = g_cancellable_new ();
|
||||||
g_thread_new ("cancel", cancel_thread, cancellable, FALSE, NULL);
|
thread = g_thread_new ("cancel", cancel_thread, cancellable, NULL);
|
||||||
|
g_assert (thread != NULL);
|
||||||
|
g_thread_unref (thread);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -288,8 +288,12 @@ main (int argc,
|
|||||||
|
|
||||||
if (cancel_timeout)
|
if (cancel_timeout)
|
||||||
{
|
{
|
||||||
|
GThread *thread;
|
||||||
|
|
||||||
cancellable = g_cancellable_new ();
|
cancellable = g_cancellable_new ();
|
||||||
g_thread_new ("cancel", cancel_thread, cancellable, FALSE, NULL);
|
thread = g_thread_new ("cancel", cancel_thread, cancellable, NULL);
|
||||||
|
g_assert (thread != NULL);
|
||||||
|
g_thread_unref (thread);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -81,8 +81,12 @@ main (int argc,
|
|||||||
|
|
||||||
if (cancel_timeout)
|
if (cancel_timeout)
|
||||||
{
|
{
|
||||||
|
GThread *thread;
|
||||||
|
|
||||||
cancellable = g_cancellable_new ();
|
cancellable = g_cancellable_new ();
|
||||||
g_thread_new ("cancel", cancel_thread, cancellable, FALSE, NULL);
|
thread = g_thread_new ("cancel", cancel_thread, cancellable, NULL);
|
||||||
|
g_assert (thread != NULL);
|
||||||
|
g_thread_unref (thread);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -128,7 +128,7 @@ create_server (GSocketFamily family,
|
|||||||
g_socket_listen (server, &error);
|
g_socket_listen (server, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
data->thread = g_thread_new ("server", server_thread, data, TRUE, &error);
|
data->thread = g_thread_new ("server", server_thread, data, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
@ -437,7 +437,7 @@ setup_with_thread_loop (Test *test,
|
|||||||
closure.test = test;
|
closure.test = test;
|
||||||
|
|
||||||
g_mutex_lock (&closure.loop_mutex);
|
g_mutex_lock (&closure.loop_mutex);
|
||||||
test->loop_thread = g_thread_new ("loop", thread_loop, &closure, TRUE, &error);
|
test->loop_thread = g_thread_new ("loop", thread_loop, &closure, &error);
|
||||||
while (!closure.started)
|
while (!closure.started)
|
||||||
g_cond_wait (&closure.loop_started, &closure.loop_mutex);
|
g_cond_wait (&closure.loop_started, &closure.loop_mutex);
|
||||||
g_mutex_unlock (&closure.loop_mutex);
|
g_mutex_unlock (&closure.loop_mutex);
|
||||||
|
@ -216,8 +216,8 @@ test_pipe_io (void)
|
|||||||
reader_cancel = g_cancellable_new ();
|
reader_cancel = g_cancellable_new ();
|
||||||
main_cancel = g_cancellable_new ();
|
main_cancel = g_cancellable_new ();
|
||||||
|
|
||||||
writer = g_thread_new ("writer", writer_thread, NULL, TRUE, NULL);
|
writer = g_thread_new ("writer", writer_thread, NULL, NULL);
|
||||||
reader = g_thread_new ("reader", reader_thread, NULL, TRUE, NULL);
|
reader = g_thread_new ("reader", reader_thread, NULL, NULL);
|
||||||
|
|
||||||
in = g_unix_input_stream_new (writer_pipe[0], TRUE);
|
in = g_unix_input_stream_new (writer_pipe[0], TRUE);
|
||||||
out = g_unix_output_stream_new (reader_pipe[1], TRUE);
|
out = g_unix_output_stream_new (reader_pipe[1], TRUE);
|
||||||
|
@ -312,16 +312,17 @@ g_deprecated_thread_proxy (gpointer data)
|
|||||||
*
|
*
|
||||||
* This function creates a new thread.
|
* This function creates a new thread.
|
||||||
*
|
*
|
||||||
* If @joinable is %TRUE, you can wait for this threads termination
|
|
||||||
* calling g_thread_join(). Otherwise the thread will just disappear
|
|
||||||
* when it terminates.
|
|
||||||
*
|
|
||||||
* The new thread executes the function @func with the argument @data.
|
* The new thread executes the function @func with the argument @data.
|
||||||
* If the thread was created successfully, it is returned.
|
* If the thread was created successfully, it is returned.
|
||||||
*
|
*
|
||||||
* @error can be %NULL to ignore errors, or non-%NULL to report errors.
|
* @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.
|
* The error is set, if and only if the function returns %NULL.
|
||||||
*
|
*
|
||||||
|
* This function returns a reference to the created thread only if
|
||||||
|
* @joinable is %TRUE. In that case, you must free this reference by
|
||||||
|
* calling g_thread_unref() or g_thread_join(). If @joinable is %FALSE
|
||||||
|
* then you should probably not touch the return value.
|
||||||
|
*
|
||||||
* Returns: the new #GThread on success
|
* Returns: the new #GThread on success
|
||||||
*
|
*
|
||||||
* Deprecated:2.32: Use g_thread_new() instead
|
* Deprecated:2.32: Use g_thread_new() instead
|
||||||
@ -332,7 +333,7 @@ g_thread_create (GThreadFunc func,
|
|||||||
gboolean joinable,
|
gboolean joinable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
return g_thread_new_internal (NULL, g_deprecated_thread_proxy, func, data, joinable, 0, error);
|
return g_thread_create_full (func, data, 0, joinable, 0, 0, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -360,11 +361,20 @@ g_thread_create_full (GThreadFunc func,
|
|||||||
GThreadPriority priority,
|
GThreadPriority priority,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
return g_thread_new_internal (NULL, g_deprecated_thread_proxy, func, data, joinable, stack_size, error);
|
GThread *thread;
|
||||||
|
|
||||||
|
thread = g_thread_new_internal (NULL, g_deprecated_thread_proxy,
|
||||||
|
func, data, stack_size, error);
|
||||||
|
|
||||||
|
if (!joinable)
|
||||||
|
{
|
||||||
|
thread->joinable = FALSE;
|
||||||
|
g_thread_unref (thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* GOnce {{{1 ------------------------------------------------------------- */
|
/* GOnce {{{1 ------------------------------------------------------------- */
|
||||||
gboolean
|
gboolean
|
||||||
g_once_init_enter_impl (volatile gsize *location)
|
g_once_init_enter_impl (volatile gsize *location)
|
||||||
|
@ -4760,7 +4760,7 @@ g_get_worker_context (void)
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
glib_worker_context = g_main_context_new ();
|
glib_worker_context = g_main_context_new ();
|
||||||
if (g_thread_new ("gmain", glib_worker_main, NULL, FALSE, &error) == NULL)
|
if (g_thread_new ("gmain", glib_worker_main, NULL, &error) == NULL)
|
||||||
g_error ("Creating GLib worker thread failed: %s\n", error->message);
|
g_error ("Creating GLib worker thread failed: %s\n", error->message);
|
||||||
|
|
||||||
g_once_init_leave (&initialised, TRUE);
|
g_once_init_leave (&initialised, TRUE);
|
||||||
|
@ -427,10 +427,6 @@
|
|||||||
* Specifies the type of the @func functions passed to
|
* Specifies the type of the @func functions passed to
|
||||||
* g_thread_new() or g_thread_new_full().
|
* g_thread_new() or g_thread_new_full().
|
||||||
*
|
*
|
||||||
* If the thread is joinable, the return value of this function
|
|
||||||
* is returned by a g_thread_join() call waiting for the thread.
|
|
||||||
* If the thread is not joinable, the return value is ignored.
|
|
||||||
*
|
|
||||||
* Returns: the return value of the thread
|
* Returns: the return value of the thread
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -725,7 +721,6 @@ g_thread_proxy (gpointer data)
|
|||||||
* @name: a name for the new thread
|
* @name: a name for the new thread
|
||||||
* @func: a function to execute in the new thread
|
* @func: a function to execute in the new thread
|
||||||
* @data: an argument to supply to the new thread
|
* @data: an argument to supply to the new thread
|
||||||
* @joinable: should this thread be joinable?
|
|
||||||
* @error: return location for error
|
* @error: return location for error
|
||||||
*
|
*
|
||||||
* This function creates a new thread. The new thread starts by invoking
|
* This function creates a new thread. The new thread starts by invoking
|
||||||
@ -736,14 +731,11 @@ g_thread_proxy (gpointer data)
|
|||||||
* a debugger. Some systems restrict the length of @name to
|
* a debugger. Some systems restrict the length of @name to
|
||||||
* 16 bytes.
|
* 16 bytes.
|
||||||
*
|
*
|
||||||
* If @joinable is %TRUE, you can wait for this thread's termination
|
|
||||||
* calling g_thread_join(). Resources for a joinable thread are not
|
|
||||||
* fully released until g_thread_join() is called for that thread.
|
|
||||||
* Otherwise the thread will just disappear when it terminates.
|
|
||||||
*
|
|
||||||
* @error can be %NULL to ignore errors, or non-%NULL to report errors.
|
* @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.
|
* The error is set, if and only if the function returns %NULL.
|
||||||
*
|
*
|
||||||
|
* You must
|
||||||
|
*
|
||||||
* Returns: the new #GThread, or %NULL if an error occurred
|
* Returns: the new #GThread, or %NULL if an error occurred
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
@ -752,10 +744,9 @@ GThread *
|
|||||||
g_thread_new (const gchar *name,
|
g_thread_new (const gchar *name,
|
||||||
GThreadFunc func,
|
GThreadFunc func,
|
||||||
gpointer data,
|
gpointer data,
|
||||||
gboolean joinable,
|
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
return g_thread_new_internal (name, g_thread_proxy, func, data, joinable, 0, error);
|
return g_thread_new_internal (name, g_thread_proxy, func, data, 0, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -763,7 +754,6 @@ g_thread_new (const gchar *name,
|
|||||||
* @name: a name for the new thread
|
* @name: a name for the new thread
|
||||||
* @func: a function to execute in the new thread
|
* @func: a function to execute in the new thread
|
||||||
* @data: an argument to supply to the new thread
|
* @data: an argument to supply to the new thread
|
||||||
* @joinable: should this thread be joinable?
|
|
||||||
* @stack_size: a stack size for the new thread
|
* @stack_size: a stack size for the new thread
|
||||||
* @error: return location for error
|
* @error: return location for error
|
||||||
*
|
*
|
||||||
@ -782,11 +772,6 @@ g_thread_new (const gchar *name,
|
|||||||
* In most cases, using g_thread_new() (which doesn't take a
|
* In most cases, using g_thread_new() (which doesn't take a
|
||||||
* @stack_size) is better.
|
* @stack_size) is better.
|
||||||
*
|
*
|
||||||
* If @joinable is %TRUE, you can wait for this thread's termination
|
|
||||||
* calling g_thread_join(). Resources for a joinable thread are not
|
|
||||||
* fully released until g_thread_join() is called for that thread.
|
|
||||||
* Otherwise the thread will just disappear when it terminates.
|
|
||||||
*
|
|
||||||
* @error can be %NULL to ignore errors, or non-%NULL to report errors.
|
* @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.
|
* The error is set, if and only if the function returns %NULL.
|
||||||
*
|
*
|
||||||
@ -798,11 +783,10 @@ GThread *
|
|||||||
g_thread_new_full (const gchar *name,
|
g_thread_new_full (const gchar *name,
|
||||||
GThreadFunc func,
|
GThreadFunc func,
|
||||||
gpointer data,
|
gpointer data,
|
||||||
gboolean joinable,
|
|
||||||
gsize stack_size,
|
gsize stack_size,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
return g_thread_new_internal (name, g_thread_proxy, func, data, joinable, stack_size, error);
|
return g_thread_new_internal (name, g_thread_proxy, func, data, stack_size, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
GThread *
|
GThread *
|
||||||
@ -810,7 +794,6 @@ g_thread_new_internal (const gchar *name,
|
|||||||
GThreadFunc proxy,
|
GThreadFunc proxy,
|
||||||
GThreadFunc func,
|
GThreadFunc func,
|
||||||
gpointer data,
|
gpointer data,
|
||||||
gboolean joinable,
|
|
||||||
gsize stack_size,
|
gsize stack_size,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
@ -822,9 +805,9 @@ g_thread_new_internal (const gchar *name,
|
|||||||
thread = g_system_thread_new (proxy, stack_size, error);
|
thread = g_system_thread_new (proxy, stack_size, error);
|
||||||
if (thread)
|
if (thread)
|
||||||
{
|
{
|
||||||
thread->ref_count = joinable ? 2 : 1;
|
thread->ref_count = 2;
|
||||||
thread->ours = TRUE;
|
thread->ours = TRUE;
|
||||||
thread->thread.joinable = joinable;
|
thread->thread.joinable = TRUE;
|
||||||
thread->thread.func = func;
|
thread->thread.func = func;
|
||||||
thread->thread.data = data;
|
thread->thread.data = data;
|
||||||
thread->name = name;
|
thread->name = name;
|
||||||
@ -840,10 +823,9 @@ g_thread_new_internal (const gchar *name,
|
|||||||
*
|
*
|
||||||
* Terminates the current thread.
|
* Terminates the current thread.
|
||||||
*
|
*
|
||||||
* If another thread is waiting for that thread using g_thread_join()
|
* If another thread is waiting for us using g_thread_join() then the
|
||||||
* and the current thread is joinable, the waiting thread will be woken
|
* waiting thread will be woken up and get @retval as the return value
|
||||||
* up and get @retval as the return value of g_thread_join(). If the
|
* of g_thread_join().
|
||||||
* current thread is not joinable, @retval is ignored.
|
|
||||||
*
|
*
|
||||||
* Calling <literal>g_thread_exit (retval)</literal> is equivalent to
|
* Calling <literal>g_thread_exit (retval)</literal> is equivalent to
|
||||||
* returning @retval from the function @func, as given to g_thread_new().
|
* returning @retval from the function @func, as given to g_thread_new().
|
||||||
@ -863,17 +845,16 @@ g_thread_exit (gpointer retval)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_thread_join:
|
* g_thread_join:
|
||||||
* @thread: a joinable #GThread
|
* @thread: a #GThread
|
||||||
*
|
*
|
||||||
* Waits until @thread finishes, i.e. the function @func, as
|
* Waits until @thread finishes, i.e. the function @func, as
|
||||||
* given to g_thread_new(), returns or g_thread_exit() is called.
|
* given to g_thread_new(), returns or g_thread_exit() is called.
|
||||||
* If @thread has already terminated, then g_thread_join()
|
* If @thread has already terminated, then g_thread_join()
|
||||||
* returns immediately. @thread must be joinable.
|
* returns immediately.
|
||||||
*
|
*
|
||||||
* Any thread can wait for any other (joinable) thread by calling
|
* Any thread can wait for any other thread by calling g_thread_join(),
|
||||||
* g_thread_join(), not just its 'creator'. Calling g_thread_join()
|
* not just its 'creator'. Calling g_thread_join() from multiple threads
|
||||||
* from multiple threads for the same @thread leads to undefined
|
* for the same @thread leads to undefined behaviour.
|
||||||
* behaviour.
|
|
||||||
*
|
*
|
||||||
* The value returned by @func or given to g_thread_exit() is
|
* The value returned by @func or given to g_thread_exit() is
|
||||||
* returned by this function.
|
* returned by this function.
|
||||||
@ -890,7 +871,6 @@ g_thread_join (GThread *thread)
|
|||||||
gpointer retval;
|
gpointer retval;
|
||||||
|
|
||||||
g_return_val_if_fail (thread, NULL);
|
g_return_val_if_fail (thread, NULL);
|
||||||
g_return_val_if_fail (thread->joinable, NULL);
|
|
||||||
|
|
||||||
g_system_thread_wait (real);
|
g_system_thread_wait (real);
|
||||||
|
|
||||||
|
@ -142,12 +142,10 @@ void g_thread_unref (GThread *thread);
|
|||||||
GThread * g_thread_new (const gchar *name,
|
GThread * g_thread_new (const gchar *name,
|
||||||
GThreadFunc func,
|
GThreadFunc func,
|
||||||
gpointer data,
|
gpointer data,
|
||||||
gboolean joinable,
|
|
||||||
GError **error);
|
GError **error);
|
||||||
GThread * g_thread_new_full (const gchar *name,
|
GThread * g_thread_new_full (const gchar *name,
|
||||||
GThreadFunc func,
|
GThreadFunc func,
|
||||||
gpointer data,
|
gpointer data,
|
||||||
gboolean joinable,
|
|
||||||
gsize stack_size,
|
gsize stack_size,
|
||||||
GError **error);
|
GError **error);
|
||||||
GThread * g_thread_self (void);
|
GThread * g_thread_self (void);
|
||||||
|
@ -411,14 +411,15 @@ g_thread_pool_start_thread (GRealThreadPool *pool,
|
|||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
GError *local_error = NULL;
|
GThread *thread;
|
||||||
|
|
||||||
/* No thread was found, we have to start a new one */
|
/* No thread was found, we have to start a new one */
|
||||||
if (!g_thread_new ("pool", g_thread_pool_thread_proxy, pool, FALSE, &local_error))
|
thread = g_thread_new ("pool", g_thread_pool_thread_proxy, pool, error);
|
||||||
{
|
|
||||||
g_propagate_error (error, local_error);
|
if (thread == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
g_thread_unref (thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See comment in g_thread_pool_thread_proxy as to why this is done
|
/* See comment in g_thread_pool_thread_proxy as to why this is done
|
||||||
|
@ -44,13 +44,13 @@ void g_system_thread_free (GRealThread *thread);
|
|||||||
G_GNUC_INTERNAL void g_system_thread_exit (void);
|
G_GNUC_INTERNAL void g_system_thread_exit (void);
|
||||||
G_GNUC_INTERNAL void g_system_thread_set_name (const gchar *name);
|
G_GNUC_INTERNAL void g_system_thread_set_name (const gchar *name);
|
||||||
|
|
||||||
G_GNUC_INTERNAL GThread *g_thread_new_internal (const gchar *name,
|
G_GNUC_INTERNAL
|
||||||
GThreadFunc proxy,
|
GThread * g_thread_new_internal (const gchar *name,
|
||||||
GThreadFunc func,
|
GThreadFunc proxy,
|
||||||
gpointer data,
|
GThreadFunc func,
|
||||||
gboolean joinable,
|
gpointer data,
|
||||||
gsize stack_size,
|
gsize stack_size,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
gpointer g_thread_proxy (gpointer thread);
|
gpointer g_thread_proxy (gpointer thread);
|
||||||
|
@ -104,7 +104,7 @@ test_once3 (void)
|
|||||||
shared = 0;
|
shared = 0;
|
||||||
|
|
||||||
for (i = 0; i < THREADS; i++)
|
for (i = 0; i < THREADS; i++)
|
||||||
threads[i] = g_thread_new ("once3", thread_func, NULL, TRUE, NULL);
|
threads[i] = g_thread_new ("once3", thread_func, NULL, NULL);
|
||||||
|
|
||||||
for (i = 0; i < THREADS; i++)
|
for (i = 0; i < THREADS; i++)
|
||||||
g_thread_join (threads[i]);
|
g_thread_join (threads[i]);
|
||||||
|
@ -50,7 +50,7 @@ test_thread1 (void)
|
|||||||
GThread *thread;
|
GThread *thread;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
thread = g_thread_new ("test", thread1_func, NULL, TRUE, &error);
|
thread = g_thread_new ("test", thread1_func, NULL, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
result = g_thread_join (thread);
|
result = g_thread_join (thread);
|
||||||
@ -71,7 +71,7 @@ test_thread2 (void)
|
|||||||
gpointer result;
|
gpointer result;
|
||||||
GThread *thread;
|
GThread *thread;
|
||||||
|
|
||||||
thread = g_thread_new ("test", thread2_func, NULL, TRUE, NULL);
|
thread = g_thread_new ("test", thread2_func, NULL, NULL);
|
||||||
|
|
||||||
g_assert (g_thread_self () != thread);
|
g_assert (g_thread_self () != thread);
|
||||||
|
|
||||||
@ -107,9 +107,9 @@ test_thread3 (void)
|
|||||||
gpointer result;
|
gpointer result;
|
||||||
GThread *thread1, *thread2, *thread3;
|
GThread *thread1, *thread2, *thread3;
|
||||||
|
|
||||||
thread1 = g_thread_new_full ("a", thread3_func, NULL, TRUE, 0, NULL);
|
thread1 = g_thread_new_full ("a", thread3_func, NULL, 0, NULL);
|
||||||
thread2 = g_thread_new_full ("b", thread3_func, thread1, TRUE, 100, NULL);
|
thread2 = g_thread_new_full ("b", thread3_func, thread1, 100, NULL);
|
||||||
thread3 = g_thread_new_full ("c", thread3_func, thread2, TRUE, 100000, NULL);
|
thread3 = g_thread_new_full ("c", thread3_func, thread2, 100000, NULL);
|
||||||
|
|
||||||
result = g_thread_join (thread3);
|
result = g_thread_join (thread3);
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ test_thread4 (void)
|
|||||||
g_error ("prlimit failed: %s\n", g_strerror (ret));
|
g_error ("prlimit failed: %s\n", g_strerror (ret));
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
thread = g_thread_new ("a", thread1_func, NULL, FALSE, &error);
|
thread = g_thread_new ("a", thread1_func, NULL, &error);
|
||||||
g_assert (thread == NULL);
|
g_assert (thread == NULL);
|
||||||
g_assert_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN);
|
g_assert_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
|
@ -210,7 +210,7 @@ test_multithreaded_dynamic_type_init (void)
|
|||||||
|
|
||||||
/* create threads */
|
/* create threads */
|
||||||
for (i = 0; i < N_THREADS; i++) {
|
for (i = 0; i < N_THREADS; i++) {
|
||||||
threads[i] = g_thread_new ("test", ref_unref_thread, (gpointer) DYNAMIC_OBJECT_TYPE, TRUE, NULL);
|
threads[i] = g_thread_new ("test", ref_unref_thread, (gpointer) DYNAMIC_OBJECT_TYPE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* execute threads */
|
/* execute threads */
|
||||||
|
@ -133,8 +133,8 @@ testcase (gconstpointer data)
|
|||||||
|
|
||||||
for (i = 0; i < THREADS; i++)
|
for (i = 0; i < THREADS; i++)
|
||||||
threads[i] = g_thread_new ("foo", thread_func,
|
threads[i] = g_thread_new ("foo", thread_func,
|
||||||
GINT_TO_POINTER (use_pointers),
|
GINT_TO_POINTER (use_pointers),
|
||||||
TRUE, NULL);
|
NULL);
|
||||||
|
|
||||||
for (i = 0; i < THREADS; i++)
|
for (i = 0; i < THREADS; i++)
|
||||||
g_thread_join (threads[i]);
|
g_thread_join (threads[i]);
|
||||||
|
@ -47,7 +47,7 @@ test_atomic (void)
|
|||||||
bucket[i] = 0;
|
bucket[i] = 0;
|
||||||
|
|
||||||
for (i = 0; i < THREADS; i++)
|
for (i = 0; i < THREADS; i++)
|
||||||
threads[i] = g_thread_new ("atomic", thread_func, GINT_TO_POINTER (i), TRUE, NULL);
|
threads[i] = g_thread_new ("atomic", thread_func, GINT_TO_POINTER (i), NULL);
|
||||||
|
|
||||||
for (i = 0; i < THREADS; i++)
|
for (i = 0; i < THREADS; i++)
|
||||||
g_thread_join (threads[i]);
|
g_thread_join (threads[i]);
|
||||||
|
@ -229,7 +229,7 @@ test_threaded (void)
|
|||||||
for (i = 0; i < NUM_THREADS; i++)
|
for (i = 0; i < NUM_THREADS; i++)
|
||||||
{
|
{
|
||||||
context_init (&contexts[i]);
|
context_init (&contexts[i]);
|
||||||
threads[i] = g_thread_new ("test", thread_func, &contexts[i], TRUE, NULL);
|
threads[i] = g_thread_new ("test", thread_func, &contexts[i], NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* dispatch tokens */
|
/* dispatch tokens */
|
||||||
|
@ -41,8 +41,7 @@ multithreaded_test_run (GThreadFunc function)
|
|||||||
{
|
{
|
||||||
GThread *thread;
|
GThread *thread;
|
||||||
|
|
||||||
thread = g_thread_new ("test", function,
|
thread = g_thread_new ("test", function, GINT_TO_POINTER (i), &error);
|
||||||
GINT_TO_POINTER (i), TRUE, &error);
|
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_ptr_array_add (threads, thread);
|
g_ptr_array_add (threads, thread);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user