Re: [gtkmm] asynchronous communication between threads
- From: Chris Vine <chris cvine freeserve co uk>
- To: Gene Ruebsamen <gene erachampion com>, gtkmm-list gnome org
- Cc: billyoc gnuyork org
- Subject: Re: [gtkmm] asynchronous communication between threads
- Date: Wed, 24 Dec 2003 20:01:15 +0000
On Wednesday 24 December 2003 4:49 pm, Gene Ruebsamen wrote:
> 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?
SigC::bind provides static binding not dynamic binding, so it will not do what
you want. One approach is for the thread emitting the signal to push the
data onto a queue (such as std::queue) before emitting the signal, and for
the receiving thread then to pop it off the queue. If you are sending
individual characters you can also use a pipe.
With std::queue you will probably need to protect the push and pop with a
mutex unless the library you happen to use is thread safe or you can
guarantee you will never be popping and pushing at the same time. With a
queue the locking is very straightforward, about as basic as you can get.
Chris.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]