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);
    }

These threads do nothing with the GUI.

Dave






________________________________
 From: Michael Torrie <torr...@gmail.com>
To: gtk-app-devel-list@gnome.org 
Sent: Wednesday, November 27, 2013 2:16 PM
Subject: Re: Delay time to spawn new threads?
 

On 11/27/2013 08:29 AM, David Buchan wrote:
> I have written a program which spawns a new thread when the user
> clicks a button. The new thread does something noticeable immediately
> after starting, so I know when the thread has begun. What I mean is,
> if I run that piece of code that is executed as a new thread, but as
> a stand-alone program, it does it's thing immediately.
> 
> However, when I have it run as a new thread when the user clicks a
> button, it takes about 1.5 seconds before it does its thing.
> 
> 
> I've done this with g_thread_create() and g_thread_new() with
> identical results. Is it normal for there to be a 1.5 sec delay, or
> have I bumbled something?

Did you initialize the thread subsystem before using threads?  Did you
use the proper semiphores around GUI calls, or better yet use g_idle_add
to schedule GUI updates in the main thread?

http://www.gtk.org/api/2.6/gdk/gdk-Threads.html
http://blog.borovsak.si/2009/06/multi-threaded-gtk-applications.html
etc

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to