LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-17-2014, 09:29 AM   #1
akseli0x61
LQ Newbie
 
Registered: Aug 2014
Distribution: Arch
Posts: 19

Rep: Reputation: Disabled
GTK multithreading


I'm writing a GTK+ application in C and I need to parse some data and load images from another thread. I found out that gdk_threads* is depricated and I should call all GDK and GTK functions from main loop. How can I achieve this? In simple words my problem is to add image widget to the window from another thread. Could I maybe execute some callback from the thread that would add the image?
 
Old 10-17-2014, 09:44 AM   #2
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
your app has something like a message queue
your background thread makes his work, eg loading the data, and when finished it posts the result to the queue
you take the data from your main loop thread.
 
Old 10-17-2014, 02:12 PM   #3
akseli0x61
LQ Newbie
 
Registered: Aug 2014
Distribution: Arch
Posts: 19

Original Poster
Rep: Reputation: Disabled
How can I use this message queue? I can't seem to find much about it. Or maybe I just don't know how to search..
 
Old 10-19-2014, 04:52 AM   #4
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
depends on your actual use case,
for example, if you want to load data in the back ground,
than start the thread that loads the data, your GUI will continue what ever is does an not block
when finished this thread sets a atomic bool to true (which has been initialized to false of course, named done or so ...)
in you main loop you add an idle call that queries done, if done, thanks for the data, no problem that on other thread does something because the other thread is finished.
this is one possible use case,
 
  


Reply

Tags
gtk, multithreading



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multithreading pratham29 Linux - Newbie 3 10-15-2013 07:55 AM
Multithreading yes or no? mishomor Linux - General 11 06-14-2011 01:38 PM
qt multithreading? suicidle_p0ptart Linux - Software 5 08-28-2007 01:54 AM
Multithreading jayashrik Programming 1 07-20-2005 04:13 AM
Strange multithreading live_dont_exist Programming 2 05-01-2005 07:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration