Re: query on create_from_file and gdk_threads_enter() and gdk_threads_leave()



On Mon, 22 Jun 2009 16:47:30 +1000
Robert Bui <vncoder msn com> wrote:
> Hello all,
> 
>    I am trying to load multiple images  (one after another) onto a
> Gtk::Image widget. I have multiple background threads that looks for
> files at different location on disk. As soon as there is a new file,
> one of these would add the filename (enqueue) to the GAsyncQueue
> shared by the threads. Once enqueue is done, the thread would fire a
> signal which in turn would call the callback function in the main
> thread to display the image. The image actually displays but the
> whole GUI just hang. No exceptions were caught.
> 
>    Now, if I enclose the code inside ondisplayDocumentSignal (from
> create_from_file() to set()) around gdk_threads_enter() and
> gdk_threads_leave(), then it seems to work, ie the images get
> displayed correctly. 1. Why is this so? 2. Am I doing it correctly?
> 3. Why do I need to do this? I thought the main thread has control of
> all the GTK widgets as well as GDK?

No, you are not doing it correctly.
 
A slot will execute in the thread which calls the signal to which it
is connected. It is just an encapsulated callback.  You need to use
Glib::Dispatcher in order for the slot to execute in the main GUI
thread.

Make sure all your calls to Glib::Dispatcher::connect(), and anything
you do to the sigc::connection object it returns, are in the main GUI
thread. If the only thing that is called in the worker threads on the
Dispatcher object is Glib::Dispatcher::emit() or
Glib::Dispatcher::operator()() then it will work fine.

Chris



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