Re: my summary on how to use gtk with threads
- From: Felix Kater <fkater googlemail com>
- To: Andrew Cowie <andrew operationaldynamics com>
- Cc: "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: Re: my summary on how to use gtk with threads
- Date: Fri, 25 May 2007 12:59:30 +0200
On Thu, 24 May 2007 01:03:25 +1000
Andrew Cowie <andrew operationaldynamics com> wrote:
http://research.operationaldynamics.com/blogs/andrew/#gtk-thread-awareness
Keep on. :-)
I didn't quite agree with this conclusion:
do not use gdk_threads_set_lock_functions() to facilitate (a)
as that was rather critical to things working [so far] for us; hang
tight until I get a chance to write up part 2, but I am going to take
the time this week to carefully consider the traps you cite and try
and see how they affect the pattern we developed.
What I warned about was ment in the context of recursive mutexes, of
course. The problem I had using gdk_threads_set_lock_functions() was
that gtk wanted to unlock the recursive mutex from time to time while
it had not been locked by it (but a thread of mine). I got aware of
this by using my own recursive mutex implementation which emits
warnings like "encountered a try to unlock although not owner" (I don't
know if you can track things of this kind using glib mutexes).
I must confess I haven't got a deep answer to this problem--I simply
assume it has to do with the gdk_threads_enter() call right
before gtk_main().
Anyway, I tried to seperate my own calls to gdk_threads_enter/leave()
from the ones envoked by gtk internally (which were, however,
triggering my recursive lock though as long as I used
gdk_threads_set_lock_functions).
However, gdk_threads_set_lock_functions() makes it impossible to
distinguish between gdk_threads_enter/leave coming from *your* threads
and from *inside gtk* -- while it is exactly this difference what is
needed (at least here) to make the recursive mutex work correctly.
So, for now, I do not use this function but rather (a) call recursive
lock/unlock functions (locking the gdk lock once only) as a substitute
for gds_threads_enter/leave () before calling any gtk functions--except
for gtk_main() where I use the direct call to gdk_threads_enter/leave,
and (b) let gtk call gdk_threads_enter/leave () internally without
notifying me so that is does not interfer with my recursive mutex.
This seems to work.
Felix
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]