Re: [gtk-list] New adventures in threading




rhfreeman <rhfreeman@micron.com> writes:

> Hi all,
> 
> Bet you can't guess I haven't done threading before? :) Sorry for all the
> questions! Having solved my previous problems with a few more
> gdk_threads_enter()/leave() I have a new problem.
> 
> The thread I spawn has a progress bar. I used to use
> while(g_main_iteration(FALSE)); to handle these events (before it was
> threaded). This has had to be removed as it causes problems with
> gdk_thread_enter/leave again - appears to be deadlocking if I have this
> between the thread statements!

> If I don't have it between the thread
> statements then I get a lot of glib warnings as iterations are being done
> out of the main loop.

These warning statements are presumably the ones you get because you
are trying to run the main loop outside the main loop. You can
only use the main loop from a single thread.

Generally, running the main loop from a subsidiary thread doesn't
really make sense - that is, you already have it running in the
other thread. You should instead just use a condition variable
or semaphore to wait for whatever you want to wait for.

> Whilst I can use gtk_main to update the progress bar - the progress bar
> appears well 5-10seconds before gtk_main is called and just sits there doing
> nothing until then.

Are you calling gdk_flush() after updating the progress bar?
See my other post from today on the subject.

> So I need a way to determine if gtk_main has been called or not - and if it
> hasn't been called then I need to call g_main_iteration instead to make sure
> it is updated. Best I have come up with so far is g_main_is_running(), but I
> need to pass an argument to it....

It would seem easiest to just keep your main loop running all the
time, make sure that thread never blocks, and do all the hard
work in other threads.

You can gtk_grab_add() on a GtkInvisible window if you need to
prevent interaction with the user until some initialization is ready.

If you really need to know whether you've called gtk_main() yet,
well, it should be pretty easy to keep track of that yourself with
a boolean guarded with a mutex.

Regards,
                                              Owen



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