[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [patch] python locking fixes
A Qui, 2003-10-02 ās 22:08, Marko Kreen escreveu:
> Making python lock recursive was not a good idea because
> it assumed that next callback will be from same plugin.
> And anyway, the recursive locks were only needed because
> xchat and python locks were both held at the same time.
Are you sure about this? Consider this example plugin:
import gtk
def someXchatHook(...):
dialog = gtk.Dialog(...)
dialog.run()
It may run into a deadlock, like this:
1. xchat hook triggers plugin
2. acquire python interpreter lock
3. create gtk dialog
4. dialog.run(): runs a recursive gtk main loop; but notice that gtk
main loop and xchat main loop are one and the same; meanwhile:
4a. some xchat event triggers another hook in this plugin
4b. acquire python interpreter lock, but
-> lock already acquired (by the same thread) => deadlock!
>
> Following patch fixes locking, so that only one of the
> locks is held at any time - except in one controlled
> situation. That means when calling xchat code, python
> lock is dropped and when calling python code, xchat lock
> is dropped. Little bit of code reorg was needed, to better
> separate xchat and python code.
I see what you're trying to do. You are thinking that if you release
the python lock before calling xchat functions, then if the plugin
reenters due to the xchat call, the lock would be free to be acquired
again. But you are forgetting that reentry can be caused by pygtk
functions too. I don't think there's any other way to make this work
without a recursive mutex.
This is why I wanted to throw away all threading stuff. This is
becoming all too complex for my liking :p
I personally just want to run pygtk plugins without fear of possible
deadlock. Whether the plugins run in separate threads and separate
globals or not I don't care.
I will conclude by stating that I liked your previous patch better.
Regards.
--
Gustavo J. A. M. Carneiro
<gjc@inescporto.pt> <gustavo@users.sourceforge.net>
--
XChat-discuss: mailing list for XChat users
Archive: http://mail.nl.linux.org/xchat-discuss/