Re: Delay time to spawn new threads?
- From: Chris Vine <chris cvine freeserve co uk>
- To: David Buchan <pdbuchan yahoo com>
- Cc: gtk-app-devel-list list <gtk-app-devel-list gnome org>
- Subject: Re: Delay time to spawn new threads?
- Date: Wed, 27 Nov 2013 20:57:37 +0000
On Wed, 27 Nov 2013 11:59:23 -0800 (PST)
David Buchan <pdbuchan yahoo com> wrote:
Hi Michael,
My 32-bit, GTK+2 version does
// Secure glib
if (!g_thread_supported ()) {
g_thread_init (NULL);
}
at the beginning, and then the thread is spawned via:
on_button1_clicked (GtkButton *button1, MyData *data)
{
GThread *thread;
GError *error = NULL;
thread = g_thread_create ((GThreadFunc) my_function, data, FALSE,
&error); if (! thread) {
g_print ("Error: Unable to create new thread for my_function()
in on_button1_clicked().%s\n", error->message); exit (EXIT_FAILURE);
}
My 64-bit, GTK+3 versions does not do the g_thread_init() call.
It spawns a new thread via:
int
on_button1_clicked (GtkButton *button1, MyData *data)
{
GThread *thread;
thread = g_thread_new ("my_function", (GThreadFunc) my_function,
data); if (! thread) {
fprintf (stderr, "Error: Unable to create new thread for
my_function() in on_button1_clicked().\n"); exit (EXIT_FAILURE);
}
Show us your my_function(): you are almost certainly doing something
wrong. Best of all, provide a complete compilable example which
demonstrates the problem. And why are you casting the function pointer
to GThreadFunc? You do not need to call g_thread_init() with glib >=
2.32, and you do with earlier versions. Prior to version 2.24
g_thread_init() had to be the first glib call. Between 2.24 and 2.30 it
had to be the first call relevant to threads.
Also, please don't top post.
Chris
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]