Re: Proper way to provide gtk+ app with asynchronous data?
- From: Russell Shaw <rjshaw netspace net au>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Proper way to provide gtk+ app with asynchronous data?
- Date: Wed, 14 Jul 2004 16:13:16 +1000
Tristan Van Berkom wrote:
Christer Palm wrote:
John Cupitt wrote:
Very simple and easy to program. I'm assuming writing 4 bytes to a
pipe is atomic, I guess. I've not had problems (even on SMP machines),
but it would be easy to add a global mutex for the pipe writers.
Oh, by the way. On a POSIX conformant system, a write to a pipe _is_
guaranteed to be atomic as long as it's no larger than PIPE_BUF (from
limits.h) bytes. So 4 bytes should be safe.
Just to point out one of the million possible solutions to this age
old problem ('cause I liked this solution alot when I heard of it, I have
to admit I haven't had the oportunity to try it myself since), you can
create your own GSource that pops off elements from a GAsyncQueue and
use that "source" in your recieving thread and in your publishing thread
you can push datum on to that queue and call `g_main_context_wakeup()'
on the recieving thread's context (ofcourse you can wrap that up in a
pretty
little convinient api...).
I'm not sure exactly how much you gain in performance by using this
aproach, but I always though that using pipes to communicate between
threads is a kind of hack.
Hi,
I'm trying to figure out how to wake up the main gtk gui thread when
new data is available in a GAsyncQueue (command_queue), so that i can
display the data in a gtk widget:
GAsyncQueue *command_queue;
static gpointer
command_thread(gpointer data)
{
...
g_async_queue_push(command_queue,command);
...
}
int
main(int argc, char *argv[])
{
gtk_init(&argc,&argv);
...
command_queue=g_async_queue_new();
GThread *thread=g_thread_create(command_thread,NULL,FALSE,NULL);
struct GSourceFuncs source_funcs;
/* what do i do here with source_funcs?*/
GSource *source=g_source_new(source_funcs,sizeof(source_funcs));
GMainContext *context=g_main_context_new();
guint sid=g_source_attach(source,context);
GMainLoop* loop=g_main_loop_new(context,FALSE);
g_main_loop_run(loop);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]