g_timeout_add_full from different thread not working

2010-02-22 Thread S Boucher
Calling g_timeout_add_full() from a different thread (note the pthread_create 
in the sample bellow) than where gtk_main() is does not work as I expect.

The timeout function only gets called if I generate events by moving the mouse. 
 If I don't move the mouse, all I see is the timeout is added repeatedly, but 
timeout_func does not get called.

I'm afraid there's something I do not understand... and thus, your help would 
be appreciated.

#include glib.h
#include gtk/gtk.h
#include gdk/gdk.h

gboolean
timeout_func (gpointer data)
{
  static int cnt=0;
  cnt ++;
  printf(%s %d %p\n, __func__, cnt, (void*)data);
  return FALSE;
}

void *
thread_func (void*arg)
{
  printf(%s()\n, __func__);
  g_timeout_add_full(G_PRIORITY_DEFAULT, 800, timeout_func, 1, NULL);
  while (1) {
sleep(2);
printf(%s() add\n, __func__);
g_timeout_add_full(G_PRIORITY_DEFAULT, 800, timeout_func, 2, NULL);
  }
}

int
main (int argc, char **argv)
{
  pthread_t t;
  gtk_init(argc, argv);
  GtkWidget *w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(w), Hello);
  gtk_widget_show_all(w);
  pthread_create(t, NULL, thread_func, NULL);
  gtk_main();
  return 0;
}



  __
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: g_timeout_add_full from different thread not working

2010-02-22 Thread Michael Cronenworth

On 02/22/2010 08:55 PM, S Boucher wrote:

Calling g_timeout_add_full() from a different thread (note the pthread_create 
in the sample bellow) than where gtk_main() is does not work as I expect.

The timeout function only gets called if I generate events by moving the mouse. 
 If I don't move the mouse, all I see is the timeout is added repeatedly, but 
timeout_func does not get called.

I'm afraid there's something I do not understand... and thus, your help would 
be appreciated.

   


I don't see a call to g_thread_init() in your example. You'll need that 
call prior to calling gtk_init().



___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: g_timeout_add_full from different thread not working

2010-02-22 Thread S Boucher


--- On Mon, 2/22/10, Michael Cronenworth m...@cchtml.com wrote:

 I don't see a call to g_thread_init() in your example.
 You'll need that call prior to calling gtk_init().

That solved the problem!
Thanks.


  __
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your 
favourite sites. Download it now
http://ca.toolbar.yahoo.com.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list