[C++-sig] Re: boost::python and threads

Vladimir Vukicevic vladimir at pobox.com
Mon Jul 7 17:31:56 CEST 2003

David Abrahams wrote:

>In addition to my earlier responses I'd like to point you at this
>posting from Patrick Hartling.  
>I'd really
>like to get all these threading issues squared away in Boost.Python,
>and I especially hope that since threading is so important in lua that
>threading integration will benefit from the luabind discussions.  In
>any case, proposals for patches to the Boost.Python core are very
>much appreciated.
Thanks for the article pointer.. I see what you meant by the guard class 
earlier.  Patrick seems to have basically implemented (in a fairly 
elegant way!) what the Python 2.3 PyGILStateEnsure/Release functions do; 
my patches to call.hpp and call_method.hpp do virtually the same thing, 
by creating a call_method_with_gil that one can use in wrappers instead 
of call_method.

The difficulty seems to be calling from python into C++, in invoke.hpp. 
 My patch took a first stab at it, but I didn't look closely enough -- 
the arguments passed to f() in the invoke() calls are all arg 
converters.  What I'd really like to have happen is for a function foo, 
to have an invoke() and an invoke_helper, where the invoke_helper has 
the exact same signature as foo but inserts Py_BEGIN_ALLOW_THREADS and 
Py_END_ALLOW_THREADS around the actual call to foo() (or, more 
accurately, the pointer to foo).  This can't happen in the actual 
invoke() call, as my patch attempts to do, because the arg converters 
need to use Python API calls (oops!).  I'm working on adding an 
invoke_helper which will do the two-step invocation, but I need to study 
the to_python interface in more detail.

    - Vlad

More information about the Cplusplus-sig mailing list