Re: more general: strategy against errors with gtk + threads
- From: Paul Pogonyshev <pogonyshev gmx net>
- To: Felix Kater <f kater2 gmx net>, gtk-app-devel-list gnome org
- Subject: Re: more general: strategy against errors with gtk + threads
- Date: Mon, 31 Jan 2005 20:26:54 +0200
Felix Kater wrote:
in my last program I use threads more extensivly than before. From time
to time it crashes with gtk errors. Now I wonder if my strategy of
avoiding gtk errors in a multi threaded environment is suitable:
Up to now I tried to narrow all changes to gtk widgets (renaming labels,
draw into drawables etc.) to one single function, which is running in
idle time. It checks "change-booleans" for each widget and reacts on
that (renames labels etc.).
Is this the right way to do?
While I think it is possible to fix your program to work without errors,
this is not something I would call "the right way." I suggest you use
asynchronous queue to send message to GUI master thread requesting some
work. You can find implementation somewhere in this list's archive.
And what is actually - in general - causing the errors?
A few possibilities that come to mind:
* You must set the "work-required" flag only after setting up all required
information (i.e. new label text.)
* You must not start setting up work information until "work-required" flag
is reset. (And you can easily waste CPU time on this...)
* You must reset the "work-required" flag in the master thread only after
the job is completed fully.
] [Thread Prev