title: Sending a glib signal across threads
body: <p>I have a thread created using pthreads that I am receiving progress notification callbacks in that thread. This is done in an external non-glib library. I want the callback to emit a glib signal event, but am not sure how to get the event onto the main (GUI) thread.</p>
  
  <p>The library code looks something like this:</p>
  
  <pre><code>struct callback
  {
      virtual void onprogress(int progress) = 0;
      virtual ~callback() {}
  };
  
  void perform_task_impl(callback *cb)
  {
      int progress = 0;
      while (long_task_is_in_progress)
      {
          // perform task
          progress += ...; // how much progress (not %) made
          if (cb) cb-&gt;onprogress(progress);
      }
  }
  
  void perform_task(callback *cb)
  {
      pthread_t threadId;
      pthread_create(&amp;threadId, NULL, perform_task_impl, cb);
  }
  </code></pre>
  
  <p>The GTK+/glib code is doing something like this:</p>
  
  <pre><code>struct MyObjectPrivate : public callback
  {
      MyObject *self;
  
      void onprogress(int progress)
      {
          // Q: how to send this to the main/GUI thread?
          g_signal_emit(self, signals[PROGRESS], 0, progress);
      }
  };
  
  void my_object_perform_task(MyObject *object)
  {
      perform_task(object-&gt;priv);
  }
  </code></pre>