Re: [gtk-list] Gtk/GLib timeouts and pthreads



>I've come into some trouble using timeouts and threads together in a GTK+
>1.2 app.
     .
     .
     .

>while(!thread_done) {
>  update spinner
>  while(gtk_events_pending()) gtk_main_iteration();
>  usleep(interframe interval);
>}
>
>pthread_join()

i am not an expert on this, but i think you will find that using:

>  while(gtk_events_pending()) gtk_main_iteration();

will never, ever cause timeouts (or idle functions) to be executed.

although there have been a lot of offhand suggestions that gtk_main()
is really just exactly the same as this loop, if you look at the code
for gtk_main() you'll see that it really isn't like this. because of
the difference, your code above doesn't ever cause the glib internals
that gtk uses to execute idle or timeout functions.

you might be able to use the fact that gtk_main() can be called
recursively here:

... create thread ...

while (!thread_done) {
      gtk_timeout_add (interframe_interval, pop_gtk_main_level, 0);
      gtk_main ();

      /* when here, you are back from a recursive call to gtk_main(),
         which presumably means that interframe_interval usecs has
	 elapsed.
       */
}

where pop_gtk_main_level looks like:

int
pop_gtk_main_level (void *ignored)

{
	gtk_quit ();
}

i am not really certain that this will work, but i think its closer to
the approach that you need.

--p



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