Re: When to use thread/fork?



On Thu, Jan 20, 2005 at 14:13:58 +0100, Miguel Angel Polo wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Jan Hudec wrote:
> | On Tue, Jan 18, 2005 at 05:02:35 +0100, Miguel Angel Polo wrote:
> |
> |>One of my application actions is time consuming, and I want to be
> |>lauched in a separate process/thread, with it's own dialog and its own
> |>progress bar. I don't want the GUI to get freezed waiting that action to
> |>complete (ugly!)
> |
> |
> | Could you just run while(Gtk::Main::events_pending) Gtk::Main::iteration;
> | That will process the currently pending X events. Just call it once in
> | a while during your process.
> 
> I'm trying this, and now the "100% cpu-consuming" method runs:
> 
> ~  while(Gtk::Main::events_pending())
> ~    Gtk::Main::iteration();

Actualy it should call Gtk::Main::interation(false) I believe. Have a look
at the argument.

> a couple of times (about once a second here, but this is cpu dependent).
> 
> But it doesn't redraw the window alone. The only thing that gets done
> now it's a Gtk::Statusbar::push() that I do just before calling that
> cpu-hungry method.

It does not redraw the window unless the window needs redrawing and
unless it knows that it needs...

Does the window need redrawing? What display-relevant code has run
between the main loop invocations?

> So I have tried something: I call my window's show_all_children() method
> before "while(events_pending) iteration;" and now it just works.

Of course. Proves the above point.

> Is there a cleaner way of getting this? Why must I order a redraw using
> show_all_children()?? Redraw events are sent to the window when it is
> overlapped and raised again or after some desktop switching (for
> example), and then Gtk::Main::iteration must attend those events.
> 
> I think my solution is inefficient, because the window is redrawn every
> time, and I want it only to be done when is needed. Meesa noob. Meesa sux ;)

Sure it does. There is a method, Gtk::Widget::queue_redraw, that tells
Gtk that the information in that particular widget has changed and needs
to be redrawn next time the main loop runs.

If the X server causes a need for redraw (e.g. because the window was
hidden or obscured and is now visible again), the main loop will know.

> Another question: What's the difference between
> Gtk::Main::iteration(true) and Gtk::Main::iteration(false)? I can't see any.

If Gtk::Main::events_pending(), then there is none. If there were no
events pending, Gtk::Main::iteration(true) would wait for some, while
Gtk::Main::iteration(false) would return right away.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb ucw cz>

Attachment: signature.asc
Description: Digital signature



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