Re: [gtkmm] asynchronous communication between threads



Quoting Paul Davis <paul linuxaudiosystems com>:

 
> Glib::Dispatcher
> 
> or you can roll your own if for some reason that doesn't appeal. use
> pipes and lock free queues of SigC::Slots. easier to use the
> ready-to-go solution.
> 
> ps. do not attempt to do GUI stuff in both threads. just notify the
> GUI thread that there is work to do.

Thanks for the reply!  I did see the Glib::Dispatcher in the API reference, as
well as the examples directory; however, I am confused as to how to pass data
between threads using the Glib::Dispatcher.

According to the API reference, the Glib::Dispatcher acts as a
SigC::Signal0<void> signal.  Doesn't this mean that one cannot bind additional
arguments to the signal using SigC::bind?  If so, how do you pass data between
threads using the dispatcher (other than using shared memory)?

For Example:

class ControlPort : public Gtk::Frame
{
public:
  ControlPort();
  void thread_function();
...
protected:
...
  Glib::Dispatcher signal_draw;
  Glib::Thread *proc_thread;
};

ControlPort::ControlPort()
{
  // connect the cross-thread signal to a slot in AudioViewport class
  // CAN I use a SigC::bind here so that I can bind additional data??
  signal_draw.connect(SigC::slot(audio,&AudioViewport::draw) );
  // create a non-joinable thread to process audio
  proc_thread = Glib::Thread::create(SigC::slot_class(*this,  
&ControlPort::thread_function), false);
...
}

void ControlPort::thread_function()
{
  // do some processing here and obtain data that needs to be passed to
AudioViewport object
  // use Glib::Dispatcher to notify AudioViewport object to update
  // HOW Can I pass data to the AudioViewport object????
  signal_draw();
}


The thread_function() runs in the 2nd thread, produces some data and then calls
the Glib::Dispatcher (ie. signal_draw()) to notify the first thread that it
needs to update the GUI.  The question is how can I pass this data from the 2nd
thread to the 1st (GUI) thread using the Glib::Dispatcher?

Hope this made sense.


p.s.  My last message may have been incomplete.

p.p.s.  Merry Christmas to everyone on the mailing list!
-- 
Gene Ruebsamen
Sales Associate
ERA Yes! Real Estate & Financial
(714) 534-4425

-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]