On Tue, 2007-10-02 at 10:51 -0400, [EMAIL PROTECTED] wrote:

> I'm still muddling my way through my first GTK application (and I'm a 
> relative newbie on all software matters).
> 
> I have the following in one of my callbacks:
> 
> timer = g_timout_add(50, (GSourceFunc) progress_update, 
> (gpointer)progressbar);
> 
> pid = fork( );
> 
> if (pid == 0)
> {
>      growPart ( );
>      exit(0);
> }
> ret = wait(NULL);
> 
> g_source_remove(timer);
> 
> ---------------
> 
> where progress_update is:
> 
> static gboolean progress_update (gpointer progressbar)
> {
>    gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar));
>    return true;
> }
> 
> ----------------
> 
> I was hoping that this would mean that the progress bar would pulse while 
> growPart() was running, but instead it waits until after (is this because 
> control hasn't been returned to gtk_main yet?) at which point it is 
> removed. If I take out the g_source_remove it runs beautifully....but only 
> after growPart has completed. How can I get around this?
> 
> Thanks so much
> 


The use of FORK is a little odd, I don't think  I've seen that used in a
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.

James,


> 
> This is an e-mail from General Dynamics Land Systems. It is for the intended 
> recipient only and may contain confidential and privileged information.  No 
> one else may read, print, store, copy, forward or act in reliance on it or 
> its attachments.  If you are not the intended recipient, please return this 
> message to the sender and delete the message and any attachments from your 
> computer. Your cooperation is appreciated.
> 
> _______________________________________________
> 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

Reply via email to