Re: When to use thread/fork?



-----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();

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.

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

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 ;)

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

|
| It's sure faster than threads, because you don't waste time on
| context-switches and synchronization. It's also easier, because you
| don't have to worry about synchronization.

Totally agree,

|
|
|>So, what's the best way to get this? Must I use glibmm threads? Maybe
|>forking is enough?? Maybe i must not fork... maybe it can be done using
|>one single thread... I'm asking because related documentation is very
|>sparse, and I'm lost.
|
|
| If you fork, you create a new process, that can only communicate with
| it's parent using standart IPC, ie. pipes, sockets and SysV IPC. So
| you'll have to set them up. And obviously the child won't have access to
| the GUI. Unix 101.
|
| So you have to use threads. IIRC you have to use whatever thread library
| Glib was compiled with, but you don't have to use the glib wrappers. You
| however want to use them for ptability.
|
|
- -------------------------------------------------------------------------------
| 						 Jan 'Bulb' Hudec <bulb ucw cz>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFB766VZSBU6dC79g0RAn89AKCaPuJoKc5w+FVau1Dn8dwXOlfzuQCeMl9x
yt3TD/OTWSjYgt+d/Lb7jJc=
=uiXb
-----END PGP SIGNATURE-----



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