[Gtk-sharp-list] ThreadNotify: The saga continues

Miguel de Icaza miguel@ximian.com
28 Oct 2002 11:10:56 -0500


Hello,

> My main use for threads is for launching processes and monitoring its
> status with the progress bar, while keeping my window attending the
> normal events. I guess that I could get around this using a function
> with gtk_timeout_add in the main loop that checks some pipe (or queue)
> that informs the status (borrowed the idea from gcombust ;). 

This kind of problem does not seem to require threads.  

What kind of progress monitoring are you doing?

You can either use timeouts for polling, or you could use GIO and watch
a file descriptor for activity (this is probably what you want) and wake
up your process only when the child process has done something.   

See, your thread monitoring the process currently has to do one of:

	* Loop in: Check and wait for some time.

	or

	* Loops busily checking.

	or

	* Block until something happens in the child (file descriptor)

Waiting busily is a bad idea because you consume CPU that you do not
really need to.  Block until something happens in child can be achieved
with GIO watches, and loop with check and wait for some time is just
gtimeout.

Miguel