Re: Non-Blocking GUI developement



Hi Melvin,

On 1/27/07, Melvin Newman <zexelon gmail com> wrote:
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.

You've still got this inside your worker thread:

	while(g_main_context_pending(g_main_context_default))
		g_main_context_iteration(g_main_context_default, FALSE);

That's going to (indirectly) do a lot of gtk_*() calls and break
everything. The worker thread should just do g_idle_add(). Your main
thread is running the man loop, your worker doesn't need to.

You're also copying to a single buffer for the version string. Is this
really safe? Can you be sure there will never be more than one worker
thread?

	data=recieve_packet(socket_id,1);
	strcpy((char *)&FUNCTION_DATA,(char *)&data.data);
	g_idle_add(update_server_version,NULL);

I'd malloc/free instead, much safer.

I wouldn't put code in a .h file either. You should break this stuff
out into a .c file to make sure you can't get multiple definitions of
functions.

You don't need the

 g_idle_add(update_progress_bar,NULL);

in your connect loop either. I guess you could send a string saying
"connecting, try #17" or something.

Finally, you need to watch out for producing stuff in the worker
faster than the main thread can process it. If you make stuff faster
than you use it up, your machine will obviously fill up and die :-)
You may need to consider some mechanism to make the main thread skip
updates if there's a backlog (perhaps this isn't an issue? I don't
know).

John



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]