Re: [gtk-list] Re: Yield?



Robert Roebling <roebling@ruf.uni-freiburg.de> writes:

> I also need a Yield() routine to keep GTK alive
> during long operations such as copying files.

You don't need yield at all if you just launch one thread to call
gtk_main(), and then make all your other X calls from other threads.

In this scenario, you do have to have a global mutex that everyone
acquires before they make any gtk call, and that they release
afterward.  You'll also need an idle proc that does something like
this so that the other threads get access to the UI:

gint
idle_proc(gpointer /*client_data*/) {
  pthread_mutex_unlock(_xprotect);
  PThread::sleep(_sleep_time);  // Turns into a call to select() with
                                // empty filesets.
  pthread_mutex_lock(_xprotect);
  return(true);
}

Note that callbacks also require special attention, you will be
holding _xprotect anytime you enter a callback, so you have to be sure
you're still holding it when you return -- i.e. if you release the
callback, make sure you re-acquire it before returning.

-- 
Rob Browning <rlb@cs.utexas.edu>
PGP fingerprint = E8 0E 0D 04 F5 21 A0 94  53 2B 97 F5 D6 4E 39 30



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