Re: Non-Blocking GUI developement
- From: "Melvin Newman" <zexelon gmail com>
- To: "John Cupitt" <jcupitt gmail com>
- Cc: gtk-list gnome org
- Subject: Re: Non-Blocking GUI developement
- Date: Sat, 27 Jan 2007 18:38:23 -0500
Here is another noob question, how bad is it to use g_idle_add() everywhere? Basically I have created multiple functions to update different parts of the gui from my main worker thread, via the g_idle_add() function.
Once again this worked fine on my multi CPU system, but when I try to run it on my sing cpu x86 system, it crashes and burns on the third call to g_idle_add(). I can make multiple calls to the same function from g_idle_add() (
i.e. repeatedly calling it in a loop) and it works fine, but if I try to make g_idle_add() calls with more than 3 functions it crashes the program on the fourth call.
I have attached the file that has the offending code, if anyone can point out where I am going so wrong, it would be much appreciated.
Once again, thank you all for you excellent help. It does seem that I am getting closer to a working gui with every pass.
Sincerely
Melvin Newman
On 1/27/07,
John Cupitt <jcupitt gmail com> wrote:
On 1/27/07, Melvin Newman <zexelon gmail com> wrote:
> I am now trying to use g_idle_add(), however I cant seem to figure out how
> to pass data into the function that g_idle_add calls.
>
> g_idle_add(update_server_version,data.data);
>
> above is the call I am making, data.data is defined as char * and no mater
> what i do, the string gets completely corrupted when it gets passed into the
> function.
I expect the string is being freed or deallocated somehow before the
main thread sees it. Try something like:
In the worker thread context:
for(;;) {
char *data = "" lots of stuff );
fill_with_information( data );
g_idle_add( update_gui, data );
}
update_gui will run in the main thread context and can make GUI calls:
gboolean update_gui( char *data )
{
// this llooks through data and pdates the GUI
update_display( data );
g_free( data );
// returning FALSE removes this idle handler
return( FALSE );
}
I guess you might want to limit the number of update-gui()s that can
queue up, but that's a fine-tuning thing.
John
Attachment:
callbacks.h
Description: Binary data
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]