> Hi,
> I'm interested to know more about that.
> Is there some source code example that I can follow?
> --
> JP
The pattern that Mathias supplied is a good one for "C". Since we are
talking STL, here is a rough sketch of the pattern that I follow for
"C++". Of course, there are many good ways to do it, and you should
change this pattern to match your requirements. For example, you may
want a thread-safe singleton task queue to handle batches of tasks in
one event. But don't forget the golden rule of event loop based gui
programs: To keep the gui responsive to the user, each event needs to be
handled quickly.
-Anthony Vallone
//------------------------------------------------------------
// call this before gtk_main to tell glib that you are multithreaded.
g_thread_init(NULL);
// define a task interface
class GuiTask {
public:
virtual void process() = 0;
virtual ~GuiTask() {}
};
// implementations of the task interface to suit your needs
class LongComputationResultsX : public GuiTask {
public:
LongComputationResultsX(results and handlers) {...}
virtual void process() {use results and handlers to update the widgets
and state}
virtual ~LongComputationResultsX() {...}
private:
results and handlers
};
class LongComputationResultsY..., Z..., etc...
// this will get called in the main event loop thread
extern "C" gboolean idleTaskFunction(gpointer userData)
GuiTask* task = (GuiTask*)userData;
task->process();
delete task;
return false;
}
// when the worker thread has something to supply to the main thread,
// call this from the worker thread
g_idle_add(&idleTaskFunction, new LongComputationResultsX(stuff));
//------------------------------------------------------------
_______________________________________________
gtk-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-list