Re: using threads with GTK+
- From: Paul Pogonyshev <pogonyshev gmx net>
- To: gtk-app-devel-list gnome org
- Subject: Re: using threads with GTK+
- Date: Wed, 24 Dec 2003 15:10:26 +0000
Russell Shaw wrote:
Paul Pogonyshev wrote:
Hi.
I'm going to use the following threads with GTK+:
- thread 1 does all GUI job (widgets etc.) and launches more threads
when needed;
- threads 2, ... (launched by 1) do some time consuming computations
and inform thread 1 once they are done so it can present the results
to user.
The only thing i'm not sure how to implement is how to let thread 1 know
when one of working threads is finished. Current best way i found while
studying GTK+ and Glib manuals is like this:
Thread 1 uses a new event source in its the main loop which pops events
from a GAsyncQueue. Once a working thread finishes it jobs, it pushes a
structure onto the queue, calls g_main_context_wakeup() to wake thread 1
up if needed, and terminates.
This does not seem to be very hard to implement, but before starting on
it, i would like to be sure i didn't miss some more simple way of
implementing the schema above.
Thread 1 can simply retrieve events from a g_async_queue with
g_async_queue_pop() or g_async_queue_timed_pop(). The finishing
threads just push an apropriate message onto the queue with
g_async_queue_push().
This is exactly what i said. And i have implemented that already, with
Tristan's blessing (thanks, Tristan :). Everything works just fine.
Paul
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]