On Thu, 2007-10-04 at 13:27 -0700, [EMAIL PROTECTED] wrote: > Thanks James for giving me my first experience with Thread programming! > I tried the code you sent me, but unfortunately, I still can't get the > progress_update > function to run, looks like it never gets called. Any idea why this > might be happening? > growPart still runs. > > Thanks, > > Vicki >
The code i offered is really high level - almost sudo code. I prefer to evaluate a fuller example, if you care to post the whole program - or email it to me and I will email it back. Things I would be interested in would be as follows; 1. did you do away with the fork() and wait() calls? 2. did you compile it with something like this - with gthread included? "# gcc -Wall `pkg-config --libs --cflags gtk+-2.0 glib-2.0 gthread-2.0` program.c " 3. Did you call g_thread_init() in main(). ? /* * Initialize GLib thread support and GTK */ g_type_init (); g_thread_init (NULL); gdk_threads_init (); gtk_init (&argc, &argv); /* create app window */ /* create progress bar dialog */ /* * enter the GTK main loop */ gdk_threads_enter (); gtk_main (); gdk_flush (); gdk_threads_leave (); return (0); 4. How long does growPart() run? longer than 100ms the g_timeout_add() is only for 50ms, and it waits 50ms before making the first call kinda short, try 250 or 400 5. Assuming your created a dialog box for the progress bar and thats is is visible it should have ran. Stick a g_debug("update"); in the progress_update() routine after the call to gtk_progress_bar_pulse() 6. I'm thinking the most likely cause is how the program was compiled. send me some code to look at! James, > > [Hide Quoted Text] > GTK program before. The ret=wait(null) causes execution to stop at that > > point and wait for growPart() to finish. A way to get around the > logistics of fork() is to use threads directly. Consider the following; > > /* globals */ > gboolean b_pulse_control = FALSE > GThread *grow_thread_id = NULL; > gint global_ret = 0; > > > b_pulse_control = TRUE; > timer = g_timeout_add(50, (GSourceFunc) progress_update, > (gpointer)progressbar); > > grow_thread_id = g_thread_create ( growPart_thread, &b_pulse_control, > TRUE, NULL); > > > static gboolean progress_update (gpointer progressbar) > { > if (b_pulse_control) > { > gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar)); > return true; > } else { > global_ret = GPOINTER_TO_INT( g_thread_join (grow_thread) ); > return FALSE; > } > > } > > static gpointer growPart_thread(gpointer b_pulse) > { > > /* do work */ > growPart(); > > *b_pulse = FALSE; > g_thread_exit( GINT_TO_POINTER( 1 ) ); > > } > > I would do the passing of control values via a structure to avoid the > use of globals, > but this should work for you. > > > ------------------------------------------ > Invent your own San Diego at sandiego.com! > > > _______________________________________________ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list