Re: Threads !!!



Anil <anil gdit iiit net> writes:

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

Try rewriting like this:

        struct MyData {
                /* data needed by draw function */
        };
        
        gboolean
        draw (gpointer data)
        {
                struct MyData *my_data = data;
        
                gdk_draw_line (...);
        
                g_free (my_data);
        
                return FALSE; /* do not call me again */
        }
        
        thread_func ()
        {
                struct MyData *my_data;
        
                /* here the program reads data from a file descriptor ... */
        
                my_data = g_new (MyData, 1);
        
                /* fill out the my_data struct */        
        
                g_idle_add (draw, my_data);
        }

The best solution is probably to avoid threads completely, though, and
instead use GIOChannels or GSources.



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