Re: Glib::Dispatcher and data transfer into main loop
- From: Andreas Volz <lists brachttal net>
- To: gtkmm-list gnome org
- Subject: Re: Glib::Dispatcher and data transfer into main loop
- Date: Sat, 19 Apr 2008 23:04:38 +0200
Am Sat, 19 Apr 2008 20:53:23 +0200 schrieb Ludwig Hähne:
> Hi Andreas,
>
> Andreas Volz wrote on 19.04.2008 17:37:
> > Any ideas how to solve that problem? I've seen no way to give data
> > to the dispatchSignal() call. So I need a member variable to
> > transfer data from the thread called function to the dispatched
> > function. I could think of a queue that saves all the incoming data
> > from the thread for later use in the dispatched function. Do you
> > think that's the best way to do it? Any other ideas?
>
> A queue protected with a (exception-safe) Mutex and a dispatcher is
> what I did in these cases:
>
> | Glib::Dispatcher dispatcher;
> | Glib::Mutex logMutex;
> | std::queue<...> pipe;
>
> Producer thread:
>
> | Glib::Mutex::Lock lock(logMutex);
> | pipe.push(ent);
> | lock.release();
> | dispatcher.emit();
>
> Consumer (main) thread:
>
> | Glib::Mutex::Lock lock(logMutex);
> | assert(pipe.empty() == false);
> | Entity ent = pipe.front();
> | pipe.pop();
> | return ent;
That's like what I thought of. It works for me. Thanks.
regards
Andreas
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]