Re: Glib::Dispatcher and data transfer into main loop



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;

Hope that helps,
Ludwig


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