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 Aug 27, 2016 1:09 am

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 

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,

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

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

The function g_idle_add() is often used to connect a signal in the main thread from another thread see 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.


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