Re: Non-Blocking GUI developement
- From: Richard Boaz <riboaz xs4all nl>
- To: "Melvin Newman" <zexelon gmail com>
- Cc: gtk-list gnome org
- Subject: Re: Non-Blocking GUI developement
- Date: Wed, 24 Jan 2007 16:24:53 +0100
Hi,
To answer your questions first:
1) updating the GUI with the 2 lines of code you indicated is correct.
2) you say, though, that the exit button is still not responsive; was
this with a single-threaded or multi-threaded version? if it was
single-threaded, then the reason is because there is only one gtk_main
() and it can only do one thing at time. If you do work in the
background in a single thread, there's no possibility for the user to
interact with it, it's busy.
Converting this to multi-threaded to achieve what you want is the way
to go:
1) You can avoid the types of crashes you spoke of in a multi-
threaded gui by sticking to the following guidelines:
1.1) do no gtk_...() calls in your background/server thread, it
should be responsible only for the background processing you require.
1.2) do all gtk_...() calls within the single thread where gtk_main()
has been invoked.
1.3) when any background thread needs to communicate with the user
(i.e., the GUI), make a call to gtk_idle_add() specifying a function
responsible for communicating the background thread's info back to
the GUI for display. gtk_idle_add() is threadable without problems
and will place the function to be called onto the mainloop queue for
next processing.
2) using pthread vs. glib's implementation: I use glib's version,
but miss one function, it seems there is no glib equivalent to
pthread_kill(), and sometimes you might need it. but there are ways
around it, in any case. i have no strong opinion here, perhaps
someone else can provide more information.
other than that you should be fine.
richard
On Jan 24, 2007, at 3:27 PM, Melvin Newman wrote:
First off I am a noob with GTK+.
Basically I am writing a program that is to interface with a server
program over a network. As such this client program has effectively
2 parts, 1) the backend code that connects to the server and
handles all the data communications, 2) the front end GUI that
presents the code to the user.
The problem that I am running into is that I cant get the gui to
update in a timely manner (a problem that allot of us GTK noobs
seem to have, but one which no one answers clearly). I have tried
the following at key places in my code:
while(gtk_events_pending())
gtk_main_iteration();
And while this does update the gui, the user still has no control
over it. For example if the user select file->exit, the menu drops
down but the exit button has no effect. Can GTK+ run multiple
signal handlers concurrently?
In my first write of this program I used pthreads however I did it
in a very very unsafe manner and the client program would
frequently crash because both gtk_main() and my thread where doing
gui operations.
My main question therefore is, how do I write a responsive gui that
can communicate in real time over the backend networking code? Is
pthread the way to go? If so, how do I guarantee that the pthread
code will work on a single processor/core machine? My last pthread
code ran ok on my dual proc desktop, but died on my single proc
laptop.
Thank you very much for any help you can provide this noob.
Sincerely
Melvin
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]