Hi all! I am looking back at the code i wrote[1] some years back and I don't seem to recall why i did somethings the way i did. One thing that i can't remember is why I am doing threads and locking in there. Given some thought, i called reading python plugin code a bit before writing xchat-guile so i looked at the source and found this comment:
/* Thread support * ============== * * The python interpreter has a global interpreter lock. Any thread * executing must acquire it before working with data accessible from * python code. Here we must also care about xchat not being * thread-safe. We do this by using an xchat lock, which protects * xchat instructions from being executed out of time (when this * plugin is not "active"). * * When xchat calls python code: * - Change the current_plugin for the executing plugin; * - Release xchat lock * - Acquire the global interpreter lock * - Make the python call * - Release the global interpreter lock * - Acquire xchat lock * * When python code calls xchat: * - Release the global interpreter lock * - Acquire xchat lock * - Restore context, if necessary * - Make the xchat call * - Release xchat lock * - Acquire the global interpreter lock * * Inside a timer, so that individual threads have a chance to run: * - Release xchat lock * - Go ahead threads. Have a nice time! * - Acquire xchat lock * */ So in those very early days of my flying lessons, I might have just assumed I need to do the same in guile plugin as well. If someone knows some better reason I did what I did, please let me know before i start removing all the ugly thread stuff and learning the importance of it the hard way. -- Regards, Zeeshan Ali (Khattak) FSF member#5124 [1] http://gitorious.org/projects/xchat-guile/repos/mainline/blobs/master/guile.c http://gitorious.org/projects/xchat-guile/repos/mainline/blobs/master/plugin-system.scm
