Embedded Threading Question

hg hansgeunsmeyer at earthlink.net
Wed Dec 4 21:51:46 EST 2002


tpdietz at hotmail.com (Tim Dietz) wrote in message news:<32355ee1.0212040738.3e7360ea at posting.google.com>...

> > How are you calling these C functions? Do the C functions call back into Python
> > (or do they have access to variables in your embedded Python app)?
> 
> Using SWIG, we create a Python module and a C++ wrapper class.  The Python
> module then has a class Foo, which we use to call methods that interface
> into the C++ Foo class.  So, in Python, I call Foo.SetValue(val) and the
> SetValue() method of the C++ Foo class is called.
> 
> Does that help to explain things better?

A little bit, it's still rather mysterious to me :) If the
non-threaded version works fine, and the threaded version doesn't, and
if the SetValue call really is the culprit, then it may be that you
have to protect the access to that value you are setting (I suppose
it's a class member, or else some global variable). I don't think SWIG
does this automatically.  So, in this case, you need to modify the
SWIG generated code, by using a lock around the access of the
variable.


Hans



More information about the Python-list mailing list