Fun with multithreaded gnome application



I've just started on my first GTK+/gnome application, and am very pleased
with the ease with which I'm making progress. However, I've just come up
against an interesting problem.

Because the application involves lengthy computations, it is essential that
I multithread it. I've discovered that making any gtk calls from anything
other than the main thread (which is the one running gtk_main()) is doomed
to failure. However, I want progress information to be displayed for one of
my computation threads. 

From reading various posts on similar situations, this is the way I intend
to solve the problem:

1. Open a pipe to communicate between the two threads
2. Send a 'message' with occasional increments in the progress gauge
   (actually a pointer to some mutex-protected shared memory to save
    time)
3. Wake up the main thread whenever a message arrives and act on it.

Firstly, does this sound like a sane solution?

Secondly, how do I arrange for the gtk main loop to watch the pipe and run a
callback function whenever something arrives?

Cheers,

Adam




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