Re: [gtk-list] gdk_thread_leave() in call back func, otherwise dead lock.



Hi Yasushi,
 
> the following code will likely deadlocked, if I don't call
> gdk_thread_leave() before pthread_join(), because:
> 
> from gtkfaq-5.html#ss5.2
> > Callbacks from GTK+ (signals) are made within the GTK+ lock.
> 
> deadlock happnes:
> 
> - loop_thread is waiting on sleep()
> - button is clicked and GDK_THREADS_ENTER() is called in
>   gdk_event_dispatch() for callback function.
> - callback function calls pthread_join() and block itself to wait
>   loop_thread.
> - loop_thread leaves sleep() and trys to GDK_THREADS_ENTER() but it's
>   already locked by callback function and block itself
> - DEADLOCK!
> 
> My question is:
> 
> - Is it ok to call gdk_thread_leave() in call-back function, if the
>   function does not call any gtk functions?

Yes, thats perfectly fine, but as long as you're blocking inside a callback
(and that is what is happening here), you have an unresponding interface. It
might be better to just set loop_going to 0 and let loop_thread() notify the
main thread via a gtk signal as the last command it executes before it closes
down, If of course loop_thread() has a very low latency like in this example,
this might be overkill. Remember however to relock the gdk-mutex before
leaving the signal handler!
 
Bye,
Sebastian
-- 
Sebastian Wilhelmi                   |            här ovanför alla molnen
mailto:wilhelmi@ira.uka.de           |     är himmlen så förunderligt blå
http://goethe.ira.uka.de/~wilhelmi   |



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