Re: gtk multithreaded apps and glib signals
- From: Todd Fisher <taf2 lehigh edu>
- To: "Brian J. Tarricone" <bjt23 cornell edu>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: gtk multithreaded apps and glib signals
- Date: Sun, 11 Jul 2004 13:32:34 -0400
Hi,
I worked on a similar project. The way I solved the problem of
sending a signal from a thread that is not in the main event loop thread
was to use g_timeout_add and polling every 2 or 3 milliseconds for
messages from the decoding thread. So, the object that is shared
between the main thread
and the decoding thread would be a GAsyncQueue. Then all you have to do
is in your idle func do a try_pop to check if any data has been pushed onto
the queue. If the data is on the queue then process it however you like
perhaps by calling g_signal_emit or some other task. If there is
nothing in the
queue then just fall through. The decoding thread would just push a
data message into the queue when its ready to send a stream-ended
signal. At least
that's basically what i did to get my decoder thread to notify the main
thread that it was time to start up another decoder after finishing a
track in my playlist.
The source code for the media player I wrote is here if you're
interested in more of the details:
http://severna.homeip.net/code.php#gtkmusic
The important parts are in play_list.cc search fro g_timeout_add.
hope, this helps
-todd
Brian J. Tarricone wrote:
hi all-
i'm getting a bit confused as to what i'm supposed to do to make sure
multithreaded gtk apps don't do evil things. i'm writing a music
player (which is a GObject), and the audio decoding and output are
handled in a separate thread (let's call this "thread #2"). when an
audio stream finishes playing, i want it to send a glib signal
("stream-ended"). obviously, thread #2 is what knows about the stream
ending, and so logically it will call g_signal_emit(). do the signal
handlers get called in thread #2, or in the main thread? if in thread
#2, i assume i have to surround any gtk calls in the signal handler
with gdk_threads_enter/leave(), correct?
if the signals are handled in thread #2, is there a way to have the
signal get handled in the main thread? perhaps using g_idle_add() or
g_timeout_add()? in that case, do i still nead the
gdk_threads_enter/leave() pair?
i'm just trying to figure out the best way to do this; any suggestions
would be appreciated.
thanks,
brian
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]