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 responses.  I did see the Glib::Dispatcher in the API reference,
as well as the examples directory.  I am currently using a dispatcher which the
analysis thread uses to signal to the GUI thread that its time to update the
drawing.

So how can I use the dispatcher to pass data from one thread to another? 
According to the API reference, the dispatcher acts as a SigC::Signal0<void>.
That means that I cannot bind (using SigC::bind) additional arguements to it,
correct?

For example:

class ControlPort : public Gtk::Frame
{
public:
  ControlPort();
  void thread_function();
protected:
  virtual void on_play_button_clicked();
  Glib::Dispatcher signal_draw;
...
}

ControlPort::ControlPort()
{
  ...
  // Connect to the cross-thread signal in AudioViewport class
  signal_draw.connect(SigC::slot(audio,&AudioViewport::draw) );
}

void ControlPort::on_play_button_clicked()
{
  // create a non-joinable thread to process audio
proc_thread=Glib::Thread::create(SigC::slot_class(*this,&ControlPort::thread_function),
false);
}

-- 
Gene Ruebsamen


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



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