1

I have a GTK+ application with a GtkTextBuffer. It uses several worker threads which perform some lengthy operations. Those threads can report their progress in a textual format. I want to show details on how a worker thread is performing. Can you please tell me how to receive input from a worker thread?

I thought that I can emit a signal "insert-text" from the worker thread, but cannot find a relevant example while googling. Any help is much appreciated.

5
  • What can't you find an example of? Commented Dec 18, 2011 at 20:29
  • An example of how to fire a signal from a worker thread. Am I allowed to do that? Commented Dec 21, 2011 at 15:27
  • It's the same as emitting a signal from the main thread - g_signal_emit() or g_signal_emit_by_name(). The signal handler is called from the main thread with the GDK lock held. Commented Dec 21, 2011 at 20:30
  • @ptomato, are you sure g_signal_emit lock is handler by Gtk ? if that's right, then what he says should do it. Commented Dec 25, 2011 at 2:10
  • @erick2red It works for me. I didn't understand the OP's question to mean that it didn't work, just that he/she couldn't find an example. Commented Dec 25, 2011 at 14:13

2 Answers 2

1

You could use GAsyncQueue for messaging between your UI and your workers thread, it is a very finished API for communication.

Sign up to request clarification or add additional context in comments.

1 Comment

I had a look at the API (thanks for suggesting that). However, it is not obvious to me how to push signals through the main loop. Puling for them (either by means of a timer or an idle processing) is inefficient. I just would like to get informed when something interesting has happened. That's why I thought about firing signals from the worker threads.
0

Classic quick and dirty: Write your status updates to a linked list (protected by some sync primitive), have the GTK main loop poll it via a timer.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.