GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Oct 25, 2014 2:57 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Pthreads and GTK
PostPosted: Fri Mar 23, 2012 2:06 pm 
Offline
Familiar Face

Joined: Tue Jan 31, 2012 10:44 am
Posts: 8
Hello,
I'm writing a GTKmm based dynamic plotting library. I am using pthreads in the library to support plotting of multiple windows by the application. Here is how it works:

Application creates a window object and calls window_init function of the library. window_init function then creates a new thread and passes the window pointer to the thread function. The thread function calls Gtk::Main::run(*win) and does dynamic plotting through a slot connected timeout function. So, for each window created by application, there is an independent thread which calls Gtk::Main and an independent slot function which does dynamic plotting at regular intervals.

Problem:
This works well only for one window. When I try to plot multiple windows simultaneously, it works sometimes but most of the times window freezes, no plotting happens. It would be really helpful if someone could provide pointers on what might be the problem here.


Top
 Profile  
 
 Post subject: Re: Pthreads and GTK
PostPosted: Sat Mar 24, 2012 6:45 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 764
Location: UK
Hi,

You have fallen into the same trap of calling GDK/GTK from multiple treads, which is unsafe.

If you look at the FAQ for gtkmm http://live.gnome.org/gtkmm/FAQ it gives you more information at the bottom.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Pthreads and GTK
PostPosted: Mon Mar 26, 2012 1:12 pm 
Offline
Familiar Face

Joined: Tue Jan 31, 2012 10:44 am
Posts: 8
Thanks for the link. I solved the problem using gdk_threads_enter() and gdk_threads_leave() calls before and after calling gtk main from threads.


Top
 Profile  
 
 Post subject: Re: Pthreads and GTK
PostPosted: Mon Mar 26, 2012 5:12 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 764
Location: UK
You should be calling gdk_threads_enter() and gdk_threads_leave() before and after every call to GDK or GTK and not just to the gtk_main(). Also as a note gdk_threads_enter() and gdk_threads_leave() may be deprecated at some point. As there is talk of removing them from GTK+ v4.

Also the sigc set of classes are not thread safe at all and MUST NOT be used across threads.

_________________
E.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group