Re: Async debugging
- From: John K Luebs <jkluebs luebsphoto com>
- To: Russell Shaw <rjshaw iprimus com au>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Async debugging
- Date: Sat, 13 Dec 2003 19:52:49 -0500
On Sat, Dec 13, 2003 at 05:34:31PM +1100, Russell Shaw wrote:
Hi,
In multi-threaded gtk code, how do i track down errors like this:
Xlib: unexpected async reply (sequence 0x12fe)!
This is a locking issue. You have some code path where you don't
call gtk_threads_enter before you call gtk functions.
You MUST acquire the GTK lock before you call GTK or GDK functions or
manipulate GTK data structures.
Remember that signal handlers are always called with the lock held.
Idle, timer, and I/O handlers are called from the glib mainloop which
knows nothing about GTK so you must acquire the GTK lock before you do
anything GTK related from within one of these handlers.
There are tools out there that help you debug locking, but I would say
that if you need to use on of these for the GUI portion of your
application that you have some serious design issues in regards to
complexity. When designing apps that have multiple threads calling the
GUI lib (something I try to avoid in the first place) you should try to
consolidate the code paths into the GUI that come from other threads so
that it is almost obvious from visual inspection that your locking is
correct. For example, if you have to call GTK from another thread in
order to update a progress bar, create a bunch of "threadsafe" calls and
only call those functions, never call GTK functions directly from worker
threads.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]