Re: Threads !!!

draw ()
	gdk_draw_line (....)

thread_func ()
	/* Here the program reads data from a file descriptor and i need 
           to plot the data */

	draw (...)

X Errors are creeping in, when i am using the above code. 
Though i kept gdk_threads_enter() and gdk_threads_leave() before and after 
draw(), there is no effect. 

In order to prevent this X errors

1. I have tried using pipes, where i send the data to be plotted from the 
thread and i placed the draw () function as an argument to the g_idle_add 
(). Now the draw () function looks like

	gdk_idle_add (draw, ...)	

	draw (..)
		select (..); /* Waiting for the data to be plotted */
		read (..);
		gdk_draw... (...);

	here select is blocking and the gui is not updated. I can keep 
timeouts in select and overcome this blocking, but this might hamper the 
performance of the application.

	How can i solve this ????

On 1 May 2002, Soeren Sandmann wrote:

> Chris <chris starforge co uk> writes:
> > How about having a single "worker" thread that does all the updating, and
> > all the other threads in your program sent it requests with the instructions
> > about what needs to be done and the data to do it? Possible implementation:
> In fact, the glib mainloop has good support for this design. Just use
> g_idle_add (function_that_does_updating, data). This way only the
> thread that runs the mainloop will do any updating. You don't even
> have to worry about locking, as g_idle_add() will do the necessary
> locking for you.
> _______________________________________________
> gnome-devel-list mailing list
> gnome-devel-list gnome org


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