Re: When to use thread/fork?



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.

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.

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

Attachment: signature.asc
Description: Digital signature



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