GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed May 22, 2013 8:34 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Redraw from other thread
PostPosted: Thu Sep 10, 2009 2:18 pm 
Offline

Joined: Thu Sep 10, 2009 2:01 pm
Posts: 2
Hi everybody!
I need help about redrawing two widgets -- a DrawingArea and a HScale. I've got a timer in a parallel thread that increments the scroll value every 300 milliseconds. I also have a callback function that draw a different "plot" in the drawarea whenever the scale value changes.
Now the problem: after changing the value with gtk_range_set_value I queue the redraw of the two widgets with gtk_widget_queue_draw, than I call the gdk_window_process_updates on the main window to effectively redraw everything. Things goes fine until I get the error "<unknown>: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.", and the program exits. I really don't know what's the matter. Here's the interested part of the code:

Code:
void scroll_timer(union sigval unused)
{
   int v, limit;

   v=gtk_range_get_value(GTK_RANGE(scale));
   limit=gtk_adjustment_get_upper(gtk_range_get_adjustment(GTK_RANGE(scale)));
   if(v==limit)
      v=0;
   else
      v++;
   gtk_range_set_value(GTK_RANGE(scale),v);

   gtk_widget_queue_draw(scale);
   gtk_widget_queue_draw(drawarea);
   gdk_window_process_updates(gtk_widget_get_window(mainwindow),TRUE);
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 10, 2009 10:10 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello and welcome to the GTK+ forums.

This is probably caused because you're using GTK+ functions from more than single thread without locking global lock, which causes race condition at certain point.

I wrote a blog post some time ago about threads and GTK+ which you may find useful: http://tadeboro.blogspot.com/2009/06/multi-threaded-gtk-applications.html.

Tadej


Top
 Profile  
 
 Post subject: Great!
PostPosted: Fri Sep 11, 2009 3:45 pm 
Offline

Joined: Thu Sep 10, 2009 2:01 pm
Posts: 2
Fantastic! Great!!!
Really thanks! You solved perfectly my problem, and you're blog is very very very usefull.

Note: I lost all my afternoon only because I was linking the program to gthread instead of gthread-2.0. :? Everything goes fine now!

Thanks again
Edoardo


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group