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

Vladimir Vukicevic vladimir at pobox.com
Sat Jul 12 02:12:58 CEST 2003


On Mon, 2003-07-07 at 13:13, David Abrahams wrote:
> Vladimir Vukicevic <vladimir at pobox.com> writes:
>  [...]

> 
> This is all very complicated sounding, and I can't tell whether it's
> still an issue in light of the guard object idea, and I have so much
> to catch up on I don't think I have time to analyze.  If there's
> still an issue here, could you boil it down a bit?

Sorry 'bout that, I was in a hurry when I wrote that and didn't manage
to explain concisely.

Essentially what I think needs to happen is the following:

1. The GIL needs to be acquired at every point that python calls into
boost::python glue code.  (Any such acquisition should be optional, such
that extensions that don't care about threads don't have to deal with
the overhead.)

2. The GIL needs to be released (threads "allowed") around every call to
a native C++ function wrapped by boost::python.  (This function should,
if it needs to call Python or boost::python API calls, acquire the GIL
itself.)

I realized that I was being quite silly in my last patch, and
implemented both a GIL guard class (as suggested) and also a threads
allow class that do the right thing in their constructors/destructors;
this simplified things tremendously.  A newer patch is attached.  It
seems to work for me, though I'm sure that I'd need to spend some time
coming up with specific test cases to be really comfortable with it.

	- Vlad

-------------- next part --------------
A non-text attachment was scrubbed...
Name: boost-python.patch
Type: text/x-patch
Size: 30564 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030711/43992762/attachment.bin>


More information about the Cplusplus-sig mailing list