GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Apr 17, 2014 12:51 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Create signal in thread and hadle it in GTKs Main Event Loop
PostPosted: Thu Nov 24, 2011 11:10 pm 
Offline

Joined: Thu Nov 24, 2011 10:53 pm
Posts: 1
Hi all!
Well, my first post here in the forum concerns signal (message) creation and handling.
It is more or less a thread producer/consumer situation.

My application starts a thread that listens on a serial COM port (under WIN32).
As soon as data is received on the COM, the thread shall create a message/signal containing the received data.
Then the GTK main loop shall handle this signal and execute a callback function that processes the received data.

I could not find really much information on the web about such an issue.
What I think may work is a combination of g_signal_new, g_signal_connect, g_signal_emit... and the like. But I have no clue which function I need axactly and to which GObject all this shall be attached since there is no graphical widget like a button intended to handle this.
I thought a trivial problem - but (at least to me) it isn't... :-/
Any help, maybe a hint showing a direction would be great!

Thanks a lot,
klausix!


Top
 Profile  
 
 Post subject: Re: Create signal in thread and hadle it in GTKs Main Event
PostPosted: Sun Nov 27, 2011 7:33 pm 
Offline
Never Seen the Sunlight

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

The function g_idle_add() is often used to connect a signal in the main thread from another thread see http://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html for more details. Just remember to return FALSE from the call-back function otherwise it will be called repeatedly.

As a note Glib is totally thread safe, but you still need to use locks if working on the same bit of data in more than one thread. GTK and GDK are thread aware, but not thread safe and calling it from more than one thread only works under X11 (with locks and plenty of care) and not WIN32.

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group