thread error under gtk 2.0



Hello i have a big question : why the seguent code run
ok under gtk 1.2 but crash under gtk 2.0?
I have notice many other problem with thread
sincronism. For an example if i make a thread that
create some widget in a window i occurs in a sync
error. Seem that gtk ignore
gdk_thread_enter()/leave(). I apply the fix suggested
in a previus mail (modify gdkwindow.c) but there is no
change. There is a bug fix ? or i make an error in
thread management?

#include <gtk/gtk.h>
#include <pthread.h>

#define _(a)  a

GtkWidget *wnd;
GtkWidget *fxd;

void *myth(void* p)
{
  GtkWidget *button1;



  gdk_threads_enter();

  button1 = gtk_button_new_with_label (_("button1"));
  gtk_widget_ref (button1);
  gtk_object_set_data_full (GTK_OBJECT (wnd),
"button1", button1,
                            (GtkDestroyNotify)
gtk_widget_unref);
  gtk_widget_show (button1);
  gtk_fixed_put (GTK_FIXED (fxd), button1, 24, 80);
  gtk_widget_set_uposition (button1, 24, 80);
  gtk_widget_set_usize (button1, 47, 22);

  gdk_threads_leave();

  for(;;);


  return NULL;
}



int main(int argc, char** argv)
{
  pthread_t th;
  GtkWidget *window1;
  GtkWidget *fixed1;
  GtkWidget *button1;


  gtk_init(&argc,&argv);

  g_thread_init(NULL);


  window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_object_set_data (GTK_OBJECT (window1),
"window1", window1);
  gtk_window_set_title (GTK_WINDOW (window1),
_("window1"));

  fixed1 = gtk_fixed_new ();
  gtk_widget_ref (fixed1);
  gtk_object_set_data_full (GTK_OBJECT (window1),
"fixed1", fixed1,
                            (GtkDestroyNotify)
gtk_widget_unref);
  gtk_widget_show (fixed1);
  gtk_container_add (GTK_CONTAINER (window1), fixed1);

  wnd = window1;
  fxd = fixed1;
  gtk_widget_show(window1);

  pthread_create(&th,NULL,myth,NULL);
 

  gtk_main();

  return 1;
}



  Bye
       Dr Hammer




______________________________________________________________________
Scarica il nuovo Yahoo! Messenger: con webcam, nuove faccine e tante altre novità.
http://it.yahoo.com/mail_it/foot/?http://it.messenger.yahoo.com/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]